This repository was archived by the owner on Feb 22, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -551,19 +551,24 @@ export class Transpiler {
551
551
this . emit ( translated ) ;
552
552
}
553
553
554
- static DART_KEYWORDS =
555
- ( 'abstract as assert async await break case catch class const continue ' +
556
- 'default deferred do dynamic else enum export extends external factory false final ' +
557
- 'finally for get if implements import in is library new null operator part rethrow return' +
558
- ' set static super switch sync this throw true try typedef var void while with yield' )
559
- . split ( / / ) ;
554
+ // For the Dart keyword list see
555
+ // https://www.dartlang.org/docs/dart-up-and-running/ch02.html#keywords
556
+ static DART_RESERVED_WORDS =
557
+ ( 'assert break case catch class const continue default do else enum extends false final ' +
558
+ 'finally for if in is new null rethrow return super switch this throw true try var void ' +
559
+ 'while with' ) . split ( / / ) ;
560
+
561
+ // These are the built-in and limited keywords.
562
+ static DART_OTHER_KEYWORDS =
563
+ ( 'abstract as async await deferred dynamic export external factory get implements import ' +
564
+ 'library operator part set static sync typedef yield' ) . split ( / / ) ;
560
565
561
566
getLibraryName ( nameForTest : string = null ) {
562
567
var parts = ( nameForTest || this . relativeFileName ) . split ( '/' ) ;
563
568
return parts . filter ( ( p ) => p . length > 0 )
564
569
. map ( ( p ) => p . replace ( / [ ^ \w . ] / g, '_' ) )
565
570
. map ( ( p ) => p . replace ( / \. [ j t ] s $ / g, '' ) )
566
- . map ( ( p ) => Transpiler . DART_KEYWORDS . indexOf ( p ) != - 1 ? '_' + p : p )
571
+ . map ( ( p ) => Transpiler . DART_RESERVED_WORDS . indexOf ( p ) != - 1 ? '_' + p : p )
567
572
. join ( '.' ) ;
568
573
}
569
574
Original file line number Diff line number Diff line change @@ -579,9 +579,12 @@ describe('transpile to dart', () => {
579
579
var res = transpiler . translateProgram ( program , 'a/b/c.ts' ) ;
580
580
chai . expect ( res ) . to . equal ( ' library a.b.c ; var x ;' ) ;
581
581
} ) ;
582
- it ( 'handles keywords ' , ( ) => {
582
+ it ( 'handles reserved words ' , ( ) => {
583
583
chai . expect ( transpiler . getLibraryName ( '/a/for/in/do/x' ) ) . to . equal ( 'a._for._in._do.x' ) ;
584
584
} ) ;
585
+ it ( 'handles built-in and limited keywords' , ( ) => {
586
+ chai . expect ( transpiler . getLibraryName ( '/as/if/sync/x' ) ) . to . equal ( 'as._if.sync.x' ) ;
587
+ } ) ;
585
588
it ( 'handles file extensions' , ( ) => {
586
589
chai . expect ( transpiler . getLibraryName ( 'a/x.ts' ) ) . to . equal ( 'a.x' ) ;
587
590
chai . expect ( transpiler . getLibraryName ( 'a/x.js' ) ) . to . equal ( 'a.x' ) ;
You can’t perform that action at this time.
0 commit comments