Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit b3c5ec8

Browse files
committed
Merge pull request #115 from chalin/chalin-0401-keyword-rework
Refine identifying keyword kind (in prep for fix)
2 parents d9852b4 + f1c2e12 commit b3c5ec8

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

lib/main.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -551,19 +551,24 @@ export class Transpiler {
551551
this.emit(translated);
552552
}
553553

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(/ /);
560565

561566
getLibraryName(nameForTest: string = null) {
562567
var parts = (nameForTest || this.relativeFileName).split('/');
563568
return parts.filter((p) => p.length > 0)
564569
.map((p) => p.replace(/[^\w.]/g, '_'))
565570
.map((p) => p.replace(/\.[jt]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)
567572
.join('.');
568573
}
569574

test/DartTest.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,12 @@ describe('transpile to dart', () => {
579579
var res = transpiler.translateProgram(program, 'a/b/c.ts');
580580
chai.expect(res).to.equal(' library a.b.c ; var x ;');
581581
});
582-
it('handles keywords', () => {
582+
it('handles reserved words', () => {
583583
chai.expect(transpiler.getLibraryName('/a/for/in/do/x')).to.equal('a._for._in._do.x');
584584
});
585+
it('handles built-in and limited keywords', () => {
586+
chai.expect(transpiler.getLibraryName('/as/if/sync/x')).to.equal('as._if.sync.x');
587+
});
585588
it('handles file extensions', () => {
586589
chai.expect(transpiler.getLibraryName('a/x.ts')).to.equal('a.x');
587590
chai.expect(transpiler.getLibraryName('a/x.js')).to.equal('a.x');

0 commit comments

Comments
 (0)