From e93b7a75ce38177c57ee0df1684fdc94d01f418e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 2 Jun 2015 14:59:46 -0700 Subject: [PATCH 01/16] Added tests. --- .../asiPreventsParsingAsAmbientExternalModule01.ts | 8 ++++++++ .../asiPreventsParsingAsAmbientExternalModule02.ts | 10 ++++++++++ .../asiPreventsParsingAsNamespace01.ts | 7 +++++++ .../asiPreventsParsingAsNamespace02.ts | 7 +++++++ .../asiPreventsParsingAsNamespace03.ts | 9 +++++++++ .../typeAliases/asiPreventsParsingAsTypeAlias01.ts | 7 +++++++ .../typeAliases/asiPreventsParsingAsTypeAlias02.ts | 9 +++++++++ 7 files changed, 57 insertions(+) create mode 100644 tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule01.ts create mode 100644 tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts create mode 100644 tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace01.ts create mode 100644 tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace02.ts create mode 100644 tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace03.ts create mode 100644 tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias01.ts create mode 100644 tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias02.ts diff --git a/tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule01.ts b/tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule01.ts new file mode 100644 index 0000000000..73dcd821f6 --- /dev/null +++ b/tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule01.ts @@ -0,0 +1,8 @@ + +var declare: number; +var module: string; + +declare // this is the identifier 'declare' +module // this is the identifier 'module' +"my external module" // this is just a string +{ } // this is a block body \ No newline at end of file diff --git a/tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts b/tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts new file mode 100644 index 0000000000..ba0b2d48d6 --- /dev/null +++ b/tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts @@ -0,0 +1,10 @@ + +var declare: number; +var module: string; + +module container { + declare // this is the identifier 'declare' + module // this is the identifier 'module' + "my external module" // this is just a string + { } // this is a block body +} \ No newline at end of file diff --git a/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace01.ts b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace01.ts new file mode 100644 index 0000000000..f3bced2be4 --- /dev/null +++ b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace01.ts @@ -0,0 +1,7 @@ + +var namespace: number; +var n: string; + +namespace // this is the identifier 'namespace' +n // this is the identifier 'n' +{ } // this is a block body \ No newline at end of file diff --git a/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace02.ts b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace02.ts new file mode 100644 index 0000000000..63004ef3b6 --- /dev/null +++ b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace02.ts @@ -0,0 +1,7 @@ + +var module: number; +var m: string; + +module // this is the identifier 'namespace' +m // this is the identifier 'm' +{ } // this is a block body \ No newline at end of file diff --git a/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace03.ts b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace03.ts new file mode 100644 index 0000000000..de560b7fff --- /dev/null +++ b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace03.ts @@ -0,0 +1,9 @@ + +var namespace: number; +var n: string; + +namespace container { + namespace // this is the identifier 'namespace' + n // this is the identifier 'n' + { } // this is a block body +} \ No newline at end of file diff --git a/tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias01.ts b/tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias01.ts new file mode 100644 index 0000000000..8c4bc6e542 --- /dev/null +++ b/tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias01.ts @@ -0,0 +1,7 @@ + +var type; +var string; +var Foo; + +type +Foo = string; \ No newline at end of file diff --git a/tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias02.ts b/tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias02.ts new file mode 100644 index 0000000000..9357dbbfe0 --- /dev/null +++ b/tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias02.ts @@ -0,0 +1,9 @@ + +var type; +var string; +var Foo; + +namespace container { + type + Foo = string; +} \ No newline at end of file From 448e8bf0c7d5adae72cfb0e12bfdae1e2a01bc4d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 2 Jun 2015 15:47:23 -0700 Subject: [PATCH 02/16] Added baselines. --- ...PreventsParsingAsAmbientExternalModule01.js | 13 +++++++++++++ ...ntsParsingAsAmbientExternalModule01.symbols | 12 ++++++++++++ ...ventsParsingAsAmbientExternalModule01.types | 12 ++++++++++++ ...ParsingAsAmbientExternalModule02.errors.txt | 16 ++++++++++++++++ ...PreventsParsingAsAmbientExternalModule02.js | 15 +++++++++++++++ .../asiPreventsParsingAsNamespace01.js | 12 ++++++++++++ .../asiPreventsParsingAsNamespace01.symbols | 13 +++++++++++++ .../asiPreventsParsingAsNamespace01.types | 13 +++++++++++++ .../asiPreventsParsingAsNamespace02.js | 12 ++++++++++++ .../asiPreventsParsingAsNamespace02.symbols | 13 +++++++++++++ .../asiPreventsParsingAsNamespace02.types | 13 +++++++++++++ .../asiPreventsParsingAsNamespace03.js | 14 ++++++++++++++ .../asiPreventsParsingAsNamespace03.symbols | 17 +++++++++++++++++ .../asiPreventsParsingAsNamespace03.types | 17 +++++++++++++++++ .../asiPreventsParsingAsTypeAlias01.js | 13 +++++++++++++ .../asiPreventsParsingAsTypeAlias01.symbols | 15 +++++++++++++++ .../asiPreventsParsingAsTypeAlias01.types | 15 +++++++++++++++ .../asiPreventsParsingAsTypeAlias02.js | 15 +++++++++++++++ .../asiPreventsParsingAsTypeAlias02.symbols | 18 ++++++++++++++++++ .../asiPreventsParsingAsTypeAlias02.types | 18 ++++++++++++++++++ 20 files changed, 286 insertions(+) create mode 100644 tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types create mode 100644 tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.errors.txt create mode 100644 tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace01.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace01.types create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace02.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace02.types create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace03.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace03.types create mode 100644 tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types create mode 100644 tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js new file mode 100644 index 0000000000..efd82f27d1 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js @@ -0,0 +1,13 @@ +//// [asiPreventsParsingAsAmbientExternalModule01.ts] + +var declare: number; +var module: string; + +declare // this is the identifier 'declare' +module // this is the identifier 'module' +"my external module" // this is just a string +{ } // this is a block body + +//// [asiPreventsParsingAsAmbientExternalModule01.js] +var declare; +var module; diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols new file mode 100644 index 0000000000..87eb8daf7e --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule01.ts === + +var declare: number; +>declare : Symbol(declare, Decl(asiPreventsParsingAsAmbientExternalModule01.ts, 1, 3)) + +var module: string; +>module : Symbol(module, Decl(asiPreventsParsingAsAmbientExternalModule01.ts, 2, 3)) + +declare // this is the identifier 'declare' +module // this is the identifier 'module' +"my external module" // this is just a string +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types new file mode 100644 index 0000000000..94a2cc8d6a --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule01.ts === + +var declare: number; +>declare : number + +var module: string; +>module : string + +declare // this is the identifier 'declare' +module // this is the identifier 'module' +"my external module" // this is just a string +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.errors.txt b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.errors.txt new file mode 100644 index 0000000000..3064b137a1 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts(8,5): error TS2435: Ambient modules cannot be nested in other modules. + + +==== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts (1 errors) ==== + + var declare: number; + var module: string; + + module container { + declare // this is the identifier 'declare' + module // this is the identifier 'module' + "my external module" // this is just a string + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2435: Ambient modules cannot be nested in other modules. + { } // this is a block body + } \ No newline at end of file diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js new file mode 100644 index 0000000000..444b4b392c --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js @@ -0,0 +1,15 @@ +//// [asiPreventsParsingAsAmbientExternalModule02.ts] + +var declare: number; +var module: string; + +module container { + declare // this is the identifier 'declare' + module // this is the identifier 'module' + "my external module" // this is just a string + { } // this is a block body +} + +//// [asiPreventsParsingAsAmbientExternalModule02.js] +var declare; +var module; diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.js b/tests/baselines/reference/asiPreventsParsingAsNamespace01.js new file mode 100644 index 0000000000..eed9769da6 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.js @@ -0,0 +1,12 @@ +//// [asiPreventsParsingAsNamespace01.ts] + +var namespace: number; +var n: string; + +namespace // this is the identifier 'namespace' +n // this is the identifier 'n' +{ } // this is a block body + +//// [asiPreventsParsingAsNamespace01.js] +var namespace; +var n; diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols new file mode 100644 index 0000000000..a2494904be --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace01.ts === + +var namespace: number; +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace01.ts, 1, 3)) + +var n: string; +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace01.ts, 2, 3), Decl(asiPreventsParsingAsNamespace01.ts, 2, 14)) + +namespace // this is the identifier 'namespace' +n // this is the identifier 'n' +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace01.ts, 2, 3), Decl(asiPreventsParsingAsNamespace01.ts, 2, 14)) + +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.types b/tests/baselines/reference/asiPreventsParsingAsNamespace01.types new file mode 100644 index 0000000000..87044c5806 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace01.ts === + +var namespace: number; +>namespace : number + +var n: string; +>n : string + +namespace // this is the identifier 'namespace' +n // this is the identifier 'n' +>n : string + +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.js b/tests/baselines/reference/asiPreventsParsingAsNamespace02.js new file mode 100644 index 0000000000..de2bdfa8a9 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.js @@ -0,0 +1,12 @@ +//// [asiPreventsParsingAsNamespace02.ts] + +var module: number; +var m: string; + +module // this is the identifier 'namespace' +m // this is the identifier 'm' +{ } // this is a block body + +//// [asiPreventsParsingAsNamespace02.js] +var module; +var m; diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols new file mode 100644 index 0000000000..70024a8de6 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace02.ts === + +var module: number; +>module : Symbol(module, Decl(asiPreventsParsingAsNamespace02.ts, 1, 3)) + +var m: string; +>m : Symbol(m, Decl(asiPreventsParsingAsNamespace02.ts, 2, 3), Decl(asiPreventsParsingAsNamespace02.ts, 2, 14)) + +module // this is the identifier 'namespace' +m // this is the identifier 'm' +>m : Symbol(m, Decl(asiPreventsParsingAsNamespace02.ts, 2, 3), Decl(asiPreventsParsingAsNamespace02.ts, 2, 14)) + +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.types b/tests/baselines/reference/asiPreventsParsingAsNamespace02.types new file mode 100644 index 0000000000..8f6dec87a0 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace02.ts === + +var module: number; +>module : number + +var m: string; +>m : string + +module // this is the identifier 'namespace' +m // this is the identifier 'm' +>m : string + +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.js b/tests/baselines/reference/asiPreventsParsingAsNamespace03.js new file mode 100644 index 0000000000..6d8b897097 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.js @@ -0,0 +1,14 @@ +//// [asiPreventsParsingAsNamespace03.ts] + +var namespace: number; +var n: string; + +namespace container { + namespace // this is the identifier 'namespace' + n // this is the identifier 'n' + { } // this is a block body +} + +//// [asiPreventsParsingAsNamespace03.js] +var namespace; +var n; diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols new file mode 100644 index 0000000000..8dfa30c17a --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace03.ts === + +var namespace: number; +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace03.ts, 1, 3)) + +var n: string; +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace03.ts, 2, 3)) + +namespace container { +>container : Symbol(container, Decl(asiPreventsParsingAsNamespace03.ts, 2, 14)) + + namespace // this is the identifier 'namespace' + n // this is the identifier 'n' +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace03.ts, 4, 21)) + + { } // this is a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.types b/tests/baselines/reference/asiPreventsParsingAsNamespace03.types new file mode 100644 index 0000000000..3742375715 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace03.ts === + +var namespace: number; +>namespace : number + +var n: string; +>n : string + +namespace container { +>container : any + + namespace // this is the identifier 'namespace' + n // this is the identifier 'n' +>n : any + + { } // this is a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js new file mode 100644 index 0000000000..33e3895fab --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js @@ -0,0 +1,13 @@ +//// [asiPreventsParsingAsTypeAlias01.ts] + +var type; +var string; +var Foo; + +type +Foo = string; + +//// [asiPreventsParsingAsTypeAlias01.js] +var type; +var string; +var Foo; diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols new file mode 100644 index 0000000000..d11c9ff5c1 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias01.ts === + +var type; +>type : Symbol(type, Decl(asiPreventsParsingAsTypeAlias01.ts, 1, 3)) + +var string; +>string : Symbol(string, Decl(asiPreventsParsingAsTypeAlias01.ts, 2, 3)) + +var Foo; +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 3), Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 8)) + +type +Foo = string; +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 3), Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 8)) + diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types new file mode 100644 index 0000000000..d112022afa --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias01.ts === + +var type; +>type : any + +var string; +>string : any + +var Foo; +>Foo : any + +type +Foo = string; +>Foo : string + diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js new file mode 100644 index 0000000000..4a8298b2bd --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js @@ -0,0 +1,15 @@ +//// [asiPreventsParsingAsTypeAlias02.ts] + +var type; +var string; +var Foo; + +namespace container { + type + Foo = string; +} + +//// [asiPreventsParsingAsTypeAlias02.js] +var type; +var string; +var Foo; diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols new file mode 100644 index 0000000000..0da8856010 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols @@ -0,0 +1,18 @@ +=== tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias02.ts === + +var type; +>type : Symbol(type, Decl(asiPreventsParsingAsTypeAlias02.ts, 1, 3)) + +var string; +>string : Symbol(string, Decl(asiPreventsParsingAsTypeAlias02.ts, 2, 3)) + +var Foo; +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias02.ts, 3, 3)) + +namespace container { +>container : Symbol(container, Decl(asiPreventsParsingAsTypeAlias02.ts, 3, 8)) + + type + Foo = string; +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias02.ts, 5, 21)) +} diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types new file mode 100644 index 0000000000..4af0721ec2 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias02.ts === + +var type; +>type : any + +var string; +>string : any + +var Foo; +>Foo : any + +namespace container { +>container : any + + type + Foo = string; +>Foo : string +} From 77306a3ea6192c7eb56cd57371001ddcb156c71f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 2 Jun 2015 17:08:51 -0700 Subject: [PATCH 03/16] Added more tests. --- .../asiPreventsParsingAsNamespace04.ts | 3 +++ .../asiPreventsParsingAsNamespace05.ts | 10 ++++++++++ 2 files changed, 13 insertions(+) create mode 100644 tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts create mode 100644 tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05.ts diff --git a/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts new file mode 100644 index 0000000000..03021576ea --- /dev/null +++ b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts @@ -0,0 +1,3 @@ + +let module = 10; +module in {} \ No newline at end of file diff --git a/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05.ts b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05.ts new file mode 100644 index 0000000000..a821dbc363 --- /dev/null +++ b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05.ts @@ -0,0 +1,10 @@ + +let namespace = 10; +namespace a.b { + export let c = 20; +} + +namespace +a.b.c +{ +} \ No newline at end of file From 70f74ad640a2f029b3df749273e58bcaa216b4f0 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 2 Jun 2015 17:31:20 -0700 Subject: [PATCH 04/16] Accepted more baselines. --- .../asiPreventsParsingAsNamespace04.errors.txt | 9 +++++++++ .../reference/asiPreventsParsingAsNamespace04.js | 8 ++++++++ .../reference/asiPreventsParsingAsNamespace05.js | 11 +++++++++++ .../asiPreventsParsingAsNamespace05.symbols | 12 ++++++++++++ .../reference/asiPreventsParsingAsNamespace05.types | 13 +++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace04.errors.txt create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace04.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace05.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace05.types diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace04.errors.txt b/tests/baselines/reference/asiPreventsParsingAsNamespace04.errors.txt new file mode 100644 index 0000000000..d0a6be446a --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace04.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts(3,8): error TS1003: Identifier expected. + + +==== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts (1 errors) ==== + + let module = 10; + module in {} + ~~ +!!! error TS1003: Identifier expected. \ No newline at end of file diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace04.js b/tests/baselines/reference/asiPreventsParsingAsNamespace04.js new file mode 100644 index 0000000000..bcd8975d46 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace04.js @@ -0,0 +1,8 @@ +//// [asiPreventsParsingAsNamespace04.ts] + +let module = 10; +module in {} + +//// [asiPreventsParsingAsNamespace04.js] +var module = 10; + in {}; diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.js b/tests/baselines/reference/asiPreventsParsingAsNamespace05.js new file mode 100644 index 0000000000..0a525179d2 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.js @@ -0,0 +1,11 @@ +//// [asiPreventsParsingAsNamespace05.ts] + +let namespace = 10; + +namespace +a.b.c +{ +} + +//// [asiPreventsParsingAsNamespace05.js] +var namespace = 10; diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols new file mode 100644 index 0000000000..65125806b6 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05.ts === + +let namespace = 10; +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace05.ts, 1, 3)) + +namespace +a.b.c +>a : Symbol(a, Decl(asiPreventsParsingAsNamespace05.ts, 1, 19)) +>b : Symbol(b, Decl(asiPreventsParsingAsNamespace05.ts, 4, 2)) +>c : Symbol(c, Decl(asiPreventsParsingAsNamespace05.ts, 4, 4)) +{ +} diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.types b/tests/baselines/reference/asiPreventsParsingAsNamespace05.types new file mode 100644 index 0000000000..f17ad1f2a1 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05.ts === + +let namespace = 10; +>namespace : number +>10 : number + +namespace +a.b.c +>a : any +>b : any +>c : any +{ +} From 3cac56af1ab7bb7c51a192a4f8ff8d4e9dbc06e6 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 3 Jun 2015 12:05:12 -0700 Subject: [PATCH 05/16] Fixed case for the 'declare' keyword. --- src/compiler/parser.ts | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 4a46e375f8..72cd3bb620 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1818,7 +1818,7 @@ module ts { if (matchesPattern) { // Report that we need an identifier. However, report it right after the dot, // and not on the next token. This is because the next token might actually - // be an identifier and the error woudl be quite confusing. + // be an identifier and the error would be quite confusing. return createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentToken*/ true, Diagnostics.Identifier_expected); } } @@ -3981,19 +3981,31 @@ module ts { return parseDebuggerStatement(); case SyntaxKind.AtToken: return parseDeclaration(); - case SyntaxKind.ConstKeyword: case SyntaxKind.DeclareKeyword: + if (lookAhead(isFollowedByIdentifierOrKeywordOnSameLine) && getDeclarationFlags() & flags) { + return parseDeclaration(); + } + break; + case SyntaxKind.ModuleKeyword: + if (lookAhead(isFollowedByIdentifierOrStringOnSameLine) && getDeclarationFlags() & flags) { + return parseDeclaration(); + } + break; + case SyntaxKind.NamespaceKeyword: + case SyntaxKind.TypeKeyword: + if (lookAhead(isFollowedByIdentifierOnSameLine) && getDeclarationFlags() & flags) { + return parseDeclaration(); + } + break; + case SyntaxKind.ConstKeyword: case SyntaxKind.EnumKeyword: case SyntaxKind.ExportKeyword: case SyntaxKind.ImportKeyword: case SyntaxKind.InterfaceKeyword: - case SyntaxKind.ModuleKeyword: - case SyntaxKind.NamespaceKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.PublicKeyword: case SyntaxKind.StaticKeyword: - case SyntaxKind.TypeKeyword: if (getDeclarationFlags() & flags) { return parseDeclaration(); } @@ -4044,6 +4056,21 @@ module ts { } } + function isFollowedByIdentifierOrKeywordOnSameLine() { + nextToken(); + return !scanner.hasPrecedingLineBreak() && isIdentifierOrKeyword(); + } + + function isFollowedByIdentifierOrStringOnSameLine() { + nextToken(); + return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token === SyntaxKind.StringLiteral); + } + + function isFollowedByIdentifierOnSameLine() { + nextToken(); + return !scanner.hasPrecedingLineBreak() && isIdentifier(); + } + function parseFunctionBlockOrSemicolon(isGenerator: boolean, diagnosticMessage?: DiagnosticMessage): Block { if (token !== SyntaxKind.OpenBraceToken && canParseSemicolon()) { parseSemicolon(); From 3cd480ddb6e5aae35d7504de9de5fb8ee4ea8b1d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 3 Jun 2015 12:05:53 -0700 Subject: [PATCH 06/16] Accepted baselines. --- ...reventsParsingAsAmbientExternalModule01.js | 4 ++++ ...tsParsingAsAmbientExternalModule01.symbols | 4 ++++ ...entsParsingAsAmbientExternalModule01.types | 6 +++++ ...arsingAsAmbientExternalModule02.errors.txt | 16 -------------- ...reventsParsingAsAmbientExternalModule02.js | 7 ++++++ ...tsParsingAsAmbientExternalModule02.symbols | 20 +++++++++++++++++ ...entsParsingAsAmbientExternalModule02.types | 22 +++++++++++++++++++ .../asiPreventsParsingAsNamespace01.js | 3 +++ .../asiPreventsParsingAsNamespace01.symbols | 6 +++-- .../asiPreventsParsingAsNamespace01.types | 2 ++ .../asiPreventsParsingAsNamespace02.js | 3 +++ .../asiPreventsParsingAsNamespace02.symbols | 6 +++-- .../asiPreventsParsingAsNamespace02.types | 2 ++ .../asiPreventsParsingAsNamespace03.js | 6 +++++ .../asiPreventsParsingAsNamespace03.symbols | 4 +++- .../asiPreventsParsingAsNamespace03.types | 6 +++-- ...asiPreventsParsingAsNamespace04.errors.txt | 9 -------- .../asiPreventsParsingAsNamespace04.js | 2 +- .../asiPreventsParsingAsNamespace04.symbols | 8 +++++++ .../asiPreventsParsingAsNamespace04.types | 11 ++++++++++ .../asiPreventsParsingAsNamespace05.js | 14 ++++++++++++ .../asiPreventsParsingAsNamespace05.symbols | 20 +++++++++++++---- .../asiPreventsParsingAsNamespace05.types | 19 +++++++++++++--- .../asiPreventsParsingAsTypeAlias01.js | 2 ++ .../asiPreventsParsingAsTypeAlias01.symbols | 9 +++++--- .../asiPreventsParsingAsTypeAlias01.types | 8 +++++-- .../asiPreventsParsingAsTypeAlias02.js | 5 +++++ .../asiPreventsParsingAsTypeAlias02.symbols | 5 ++++- .../asiPreventsParsingAsTypeAlias02.types | 8 +++++-- .../reservedNamesInAliases.errors.txt | 13 ++++++----- .../reference/reservedNamesInAliases.js | 2 ++ .../reference/reservedWords2.errors.txt | 10 ++++----- tests/baselines/reference/reservedWords2.js | 1 + 33 files changed, 205 insertions(+), 58 deletions(-) delete mode 100644 tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.errors.txt create mode 100644 tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.types delete mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace04.errors.txt create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace04.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace04.types diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js index efd82f27d1..caf90acae5 100644 --- a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js @@ -11,3 +11,7 @@ module // this is the identifier 'module' //// [asiPreventsParsingAsAmbientExternalModule01.js] var declare; var module; +declare; // this is the identifier 'declare' +module; // this is the identifier 'module' +"my external module"; // this is just a string +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols index 87eb8daf7e..c35432b7ec 100644 --- a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols @@ -7,6 +7,10 @@ var module: string; >module : Symbol(module, Decl(asiPreventsParsingAsAmbientExternalModule01.ts, 2, 3)) declare // this is the identifier 'declare' +>declare : Symbol(declare, Decl(asiPreventsParsingAsAmbientExternalModule01.ts, 1, 3)) + module // this is the identifier 'module' +>module : Symbol(module, Decl(asiPreventsParsingAsAmbientExternalModule01.ts, 2, 3)) + "my external module" // this is just a string { } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types index 94a2cc8d6a..3e6aade9a2 100644 --- a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types @@ -7,6 +7,12 @@ var module: string; >module : string declare // this is the identifier 'declare' +>declare : number + module // this is the identifier 'module' +>module : string + "my external module" // this is just a string +>"my external module" : string + { } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.errors.txt b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.errors.txt deleted file mode 100644 index 3064b137a1..0000000000 --- a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts(8,5): error TS2435: Ambient modules cannot be nested in other modules. - - -==== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts (1 errors) ==== - - var declare: number; - var module: string; - - module container { - declare // this is the identifier 'declare' - module // this is the identifier 'module' - "my external module" // this is just a string - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2435: Ambient modules cannot be nested in other modules. - { } // this is a block body - } \ No newline at end of file diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js index 444b4b392c..20e2693ba7 100644 --- a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js @@ -13,3 +13,10 @@ module container { //// [asiPreventsParsingAsAmbientExternalModule02.js] var declare; var module; +var container; +(function (container) { + declare; // this is the identifier 'declare' + module; // this is the identifier 'module' + "my external module"; // this is just a string + { } // this is a block body +})(container || (container = {})); diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.symbols b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.symbols new file mode 100644 index 0000000000..ed97f39fc1 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.symbols @@ -0,0 +1,20 @@ +=== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts === + +var declare: number; +>declare : Symbol(declare, Decl(asiPreventsParsingAsAmbientExternalModule02.ts, 1, 3)) + +var module: string; +>module : Symbol(module, Decl(asiPreventsParsingAsAmbientExternalModule02.ts, 2, 3)) + +module container { +>container : Symbol(container, Decl(asiPreventsParsingAsAmbientExternalModule02.ts, 2, 19)) + + declare // this is the identifier 'declare' +>declare : Symbol(declare, Decl(asiPreventsParsingAsAmbientExternalModule02.ts, 1, 3)) + + module // this is the identifier 'module' +>module : Symbol(module, Decl(asiPreventsParsingAsAmbientExternalModule02.ts, 2, 3)) + + "my external module" // this is just a string + { } // this is a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.types b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.types new file mode 100644 index 0000000000..6767185399 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts === + +var declare: number; +>declare : number + +var module: string; +>module : string + +module container { +>container : typeof container + + declare // this is the identifier 'declare' +>declare : number + + module // this is the identifier 'module' +>module : string + + "my external module" // this is just a string +>"my external module" : string + + { } // this is a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.js b/tests/baselines/reference/asiPreventsParsingAsNamespace01.js index eed9769da6..282d9dd1c7 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace01.js +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.js @@ -10,3 +10,6 @@ n // this is the identifier 'n' //// [asiPreventsParsingAsNamespace01.js] var namespace; var n; +namespace; // this is the identifier 'namespace' +n; // this is the identifier 'n' +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols index a2494904be..b196d73335 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols @@ -4,10 +4,12 @@ var namespace: number; >namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace01.ts, 1, 3)) var n: string; ->n : Symbol(n, Decl(asiPreventsParsingAsNamespace01.ts, 2, 3), Decl(asiPreventsParsingAsNamespace01.ts, 2, 14)) +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace01.ts, 2, 3)) namespace // this is the identifier 'namespace' +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace01.ts, 1, 3)) + n // this is the identifier 'n' ->n : Symbol(n, Decl(asiPreventsParsingAsNamespace01.ts, 2, 3), Decl(asiPreventsParsingAsNamespace01.ts, 2, 14)) +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace01.ts, 2, 3)) { } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.types b/tests/baselines/reference/asiPreventsParsingAsNamespace01.types index 87044c5806..417a96dbed 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace01.types +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.types @@ -7,6 +7,8 @@ var n: string; >n : string namespace // this is the identifier 'namespace' +>namespace : number + n // this is the identifier 'n' >n : string diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.js b/tests/baselines/reference/asiPreventsParsingAsNamespace02.js index de2bdfa8a9..514a026dc7 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace02.js +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.js @@ -10,3 +10,6 @@ m // this is the identifier 'm' //// [asiPreventsParsingAsNamespace02.js] var module; var m; +module; // this is the identifier 'namespace' +m; // this is the identifier 'm' +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols index 70024a8de6..a3bb37c73b 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols @@ -4,10 +4,12 @@ var module: number; >module : Symbol(module, Decl(asiPreventsParsingAsNamespace02.ts, 1, 3)) var m: string; ->m : Symbol(m, Decl(asiPreventsParsingAsNamespace02.ts, 2, 3), Decl(asiPreventsParsingAsNamespace02.ts, 2, 14)) +>m : Symbol(m, Decl(asiPreventsParsingAsNamespace02.ts, 2, 3)) module // this is the identifier 'namespace' +>module : Symbol(module, Decl(asiPreventsParsingAsNamespace02.ts, 1, 3)) + m // this is the identifier 'm' ->m : Symbol(m, Decl(asiPreventsParsingAsNamespace02.ts, 2, 3), Decl(asiPreventsParsingAsNamespace02.ts, 2, 14)) +>m : Symbol(m, Decl(asiPreventsParsingAsNamespace02.ts, 2, 3)) { } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.types b/tests/baselines/reference/asiPreventsParsingAsNamespace02.types index 8f6dec87a0..e9e1433be7 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace02.types +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.types @@ -7,6 +7,8 @@ var m: string; >m : string module // this is the identifier 'namespace' +>module : number + m // this is the identifier 'm' >m : string diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.js b/tests/baselines/reference/asiPreventsParsingAsNamespace03.js index 6d8b897097..3c27694f5c 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace03.js +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.js @@ -12,3 +12,9 @@ namespace container { //// [asiPreventsParsingAsNamespace03.js] var namespace; var n; +var container; +(function (container) { + namespace; // this is the identifier 'namespace' + n; // this is the identifier 'n' + { } // this is a block body +})(container || (container = {})); diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols index 8dfa30c17a..e77d012a1b 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols @@ -10,8 +10,10 @@ namespace container { >container : Symbol(container, Decl(asiPreventsParsingAsNamespace03.ts, 2, 14)) namespace // this is the identifier 'namespace' +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace03.ts, 1, 3)) + n // this is the identifier 'n' ->n : Symbol(n, Decl(asiPreventsParsingAsNamespace03.ts, 4, 21)) +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace03.ts, 2, 3)) { } // this is a block body } diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.types b/tests/baselines/reference/asiPreventsParsingAsNamespace03.types index 3742375715..f119a789e1 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace03.types +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.types @@ -7,11 +7,13 @@ var n: string; >n : string namespace container { ->container : any +>container : typeof container namespace // this is the identifier 'namespace' +>namespace : number + n // this is the identifier 'n' ->n : any +>n : string { } // this is a block body } diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace04.errors.txt b/tests/baselines/reference/asiPreventsParsingAsNamespace04.errors.txt deleted file mode 100644 index d0a6be446a..0000000000 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace04.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts(3,8): error TS1003: Identifier expected. - - -==== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts (1 errors) ==== - - let module = 10; - module in {} - ~~ -!!! error TS1003: Identifier expected. \ No newline at end of file diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace04.js b/tests/baselines/reference/asiPreventsParsingAsNamespace04.js index bcd8975d46..704c8893e7 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace04.js +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace04.js @@ -5,4 +5,4 @@ module in {} //// [asiPreventsParsingAsNamespace04.js] var module = 10; - in {}; +module in {}; diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace04.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace04.symbols new file mode 100644 index 0000000000..60d1f8fcc4 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace04.symbols @@ -0,0 +1,8 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts === + +let module = 10; +>module : Symbol(module, Decl(asiPreventsParsingAsNamespace04.ts, 1, 3)) + +module in {} +>module : Symbol(module, Decl(asiPreventsParsingAsNamespace04.ts, 1, 3)) + diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace04.types b/tests/baselines/reference/asiPreventsParsingAsNamespace04.types new file mode 100644 index 0000000000..3fa2a448cf --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace04.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts === + +let module = 10; +>module : number +>10 : number + +module in {} +>module in {} : boolean +>module : number +>{} : {} + diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.js b/tests/baselines/reference/asiPreventsParsingAsNamespace05.js index 0a525179d2..35f557328c 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace05.js +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.js @@ -1,6 +1,9 @@ //// [asiPreventsParsingAsNamespace05.ts] let namespace = 10; +namespace a.b { + export let c = 20; +} namespace a.b.c @@ -9,3 +12,14 @@ a.b.c //// [asiPreventsParsingAsNamespace05.js] var namespace = 10; +var a; +(function (a) { + var b; + (function (b) { + b.c = 20; + })(b = a.b || (a.b = {})); +})(a || (a = {})); +namespace; +a.b.c; +{ +} diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols index 65125806b6..47f05862b0 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols @@ -3,10 +3,22 @@ let namespace = 10; >namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace05.ts, 1, 3)) -namespace -a.b.c +namespace a.b { >a : Symbol(a, Decl(asiPreventsParsingAsNamespace05.ts, 1, 19)) ->b : Symbol(b, Decl(asiPreventsParsingAsNamespace05.ts, 4, 2)) ->c : Symbol(c, Decl(asiPreventsParsingAsNamespace05.ts, 4, 4)) +>b : Symbol(b, Decl(asiPreventsParsingAsNamespace05.ts, 2, 12)) + + export let c = 20; +>c : Symbol(c, Decl(asiPreventsParsingAsNamespace05.ts, 3, 14)) +} + +namespace +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace05.ts, 1, 3)) + +a.b.c +>a.b.c : Symbol(a.b.c, Decl(asiPreventsParsingAsNamespace05.ts, 3, 14)) +>a.b : Symbol(a.b, Decl(asiPreventsParsingAsNamespace05.ts, 2, 12)) +>a : Symbol(a, Decl(asiPreventsParsingAsNamespace05.ts, 1, 19)) +>b : Symbol(a.b, Decl(asiPreventsParsingAsNamespace05.ts, 2, 12)) +>c : Symbol(a.b.c, Decl(asiPreventsParsingAsNamespace05.ts, 3, 14)) { } diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.types b/tests/baselines/reference/asiPreventsParsingAsNamespace05.types index f17ad1f2a1..515147c109 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace05.types +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.types @@ -4,10 +4,23 @@ let namespace = 10; >namespace : number >10 : number +namespace a.b { +>a : typeof a +>b : typeof b + + export let c = 20; +>c : number +>20 : number +} + namespace +>namespace : number + a.b.c ->a : any ->b : any ->c : any +>a.b.c : number +>a.b : typeof a.b +>a : typeof a +>b : typeof a.b +>c : number { } diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js index 33e3895fab..b05988290c 100644 --- a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js @@ -11,3 +11,5 @@ Foo = string; var type; var string; var Foo; +type; +Foo = string; diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols index d11c9ff5c1..fa82d53ac7 100644 --- a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols @@ -7,9 +7,12 @@ var string; >string : Symbol(string, Decl(asiPreventsParsingAsTypeAlias01.ts, 2, 3)) var Foo; ->Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 3), Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 8)) +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 3)) type -Foo = string; ->Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 3), Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 8)) +>type : Symbol(type, Decl(asiPreventsParsingAsTypeAlias01.ts, 1, 3)) + +Foo = string; +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 3)) +>string : Symbol(string, Decl(asiPreventsParsingAsTypeAlias01.ts, 2, 3)) diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types index d112022afa..7492a698e3 100644 --- a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types @@ -10,6 +10,10 @@ var Foo; >Foo : any type -Foo = string; ->Foo : string +>type : any + +Foo = string; +>Foo = string : any +>Foo : any +>string : any diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js index 4a8298b2bd..eae9898c8d 100644 --- a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js @@ -13,3 +13,8 @@ namespace container { var type; var string; var Foo; +var container; +(function (container) { + type; + Foo = string; +})(container || (container = {})); diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols index 0da8856010..4b83dba4c5 100644 --- a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols @@ -13,6 +13,9 @@ namespace container { >container : Symbol(container, Decl(asiPreventsParsingAsTypeAlias02.ts, 3, 8)) type +>type : Symbol(type, Decl(asiPreventsParsingAsTypeAlias02.ts, 1, 3)) + Foo = string; ->Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias02.ts, 5, 21)) +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias02.ts, 3, 3)) +>string : Symbol(string, Decl(asiPreventsParsingAsTypeAlias02.ts, 2, 3)) } diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types index 4af0721ec2..1e6c7a8caf 100644 --- a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types @@ -10,9 +10,13 @@ var Foo; >Foo : any namespace container { ->container : any +>container : typeof container type +>type : any + Foo = string; ->Foo : string +>Foo = string : any +>Foo : any +>string : any } diff --git a/tests/baselines/reference/reservedNamesInAliases.errors.txt b/tests/baselines/reference/reservedNamesInAliases.errors.txt index 277e06111c..5c17158053 100644 --- a/tests/baselines/reference/reservedNamesInAliases.errors.txt +++ b/tests/baselines/reference/reservedNamesInAliases.errors.txt @@ -2,12 +2,13 @@ tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(2,6): error tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(3,6): error TS2457: Type alias name cannot be 'number' tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(4,6): error TS2457: Type alias name cannot be 'boolean' tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(5,6): error TS2457: Type alias name cannot be 'string' -tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,6): error TS1003: Identifier expected. -tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,11): error TS1005: ';' expected. +tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,1): error TS2304: Cannot find name 'type'. +tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,6): error TS1005: ';' expected. +tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,11): error TS1109: Expression expected. tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,13): error TS2304: Cannot find name 'I'. -==== tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts (7 errors) ==== +==== tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts (8 errors) ==== interface I {} type any = I; ~~~ @@ -22,9 +23,11 @@ tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,13): error ~~~~~~ !!! error TS2457: Type alias name cannot be 'string' type void = I; + ~~~~ +!!! error TS2304: Cannot find name 'type'. ~~~~ -!!! error TS1003: Identifier expected. - ~ !!! error TS1005: ';' expected. + ~ +!!! error TS1109: Expression expected. ~ !!! error TS2304: Cannot find name 'I'. \ No newline at end of file diff --git a/tests/baselines/reference/reservedNamesInAliases.js b/tests/baselines/reference/reservedNamesInAliases.js index 773cc3ca84..4ebc3bdb95 100644 --- a/tests/baselines/reference/reservedNamesInAliases.js +++ b/tests/baselines/reference/reservedNamesInAliases.js @@ -7,4 +7,6 @@ type string = I; type void = I; //// [reservedNamesInAliases.js] +type; +void ; I; diff --git a/tests/baselines/reference/reservedWords2.errors.txt b/tests/baselines/reference/reservedWords2.errors.txt index 471eef4710..090b2d0d43 100644 --- a/tests/baselines/reference/reservedWords2.errors.txt +++ b/tests/baselines/reference/reservedWords2.errors.txt @@ -13,8 +13,8 @@ tests/cases/compiler/reservedWords2.ts(4,12): error TS1109: Expression expected. tests/cases/compiler/reservedWords2.ts(5,9): error TS2300: Duplicate identifier '(Missing)'. tests/cases/compiler/reservedWords2.ts(5,10): error TS1003: Identifier expected. tests/cases/compiler/reservedWords2.ts(5,18): error TS1005: '=>' expected. -tests/cases/compiler/reservedWords2.ts(6,7): error TS2300: Duplicate identifier '(Missing)'. -tests/cases/compiler/reservedWords2.ts(6,8): error TS1003: Identifier expected. +tests/cases/compiler/reservedWords2.ts(6,1): error TS2304: Cannot find name 'module'. +tests/cases/compiler/reservedWords2.ts(6,8): error TS1005: ';' expected. tests/cases/compiler/reservedWords2.ts(7,11): error TS2300: Duplicate identifier '(Missing)'. tests/cases/compiler/reservedWords2.ts(7,11): error TS1005: ':' expected. tests/cases/compiler/reservedWords2.ts(7,19): error TS2300: Duplicate identifier '(Missing)'. @@ -68,10 +68,10 @@ tests/cases/compiler/reservedWords2.ts(10,6): error TS1003: Identifier expected. ~ !!! error TS1005: '=>' expected. module void {} - -!!! error TS2300: Duplicate identifier '(Missing)'. + ~~~~~~ +!!! error TS2304: Cannot find name 'module'. ~~~~ -!!! error TS1003: Identifier expected. +!!! error TS1005: ';' expected. var {while, return} = { while: 1, return: 2 }; !!! error TS2300: Duplicate identifier '(Missing)'. diff --git a/tests/baselines/reference/reservedWords2.js b/tests/baselines/reference/reservedWords2.js index 6d5a5f530c..fb90a718ec 100644 --- a/tests/baselines/reference/reservedWords2.js +++ b/tests/baselines/reference/reservedWords2.js @@ -23,6 +23,7 @@ var ; typeof ; 10; throw function () { }; +module; void {}; var _a = { while: 1, return: 2 }, = _a.while, = _a.return; var _b = { this: 1, switch: { continue: 2 } }, = _b.this, = _b.switch.continue; From 3fe308d2a6b642704942cb4b1ee8fe8438d22e3f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 3 Jun 2015 13:46:13 -0700 Subject: [PATCH 07/16] Added an explanation for the lookahead. --- src/compiler/parser.ts | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 72cd3bb620..914952d516 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3973,7 +3973,7 @@ module ts { case SyntaxKind.ThrowKeyword: return parseThrowStatement(); case SyntaxKind.TryKeyword: - // Include the next two for error recovery. + // Include 'catch' and 'finally' for error recovery. case SyntaxKind.CatchKeyword: case SyntaxKind.FinallyKeyword: return parseTryStatement(); @@ -3981,6 +3981,33 @@ module ts { return parseDebuggerStatement(); case SyntaxKind.AtToken: return parseDeclaration(); + + case SyntaxKind.ConstKeyword: + case SyntaxKind.EnumKeyword: + case SyntaxKind.ExportKeyword: + case SyntaxKind.ImportKeyword: + case SyntaxKind.InterfaceKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: + case SyntaxKind.PublicKeyword: + case SyntaxKind.StaticKeyword: + if (getDeclarationFlags() & flags) { + return parseDeclaration(); + } + break; + + // 'declare', 'module', 'namespace', and 'type' are all legal JavaScript identifiers when ASI + // takes effect. In such cases, we cannot parse out the "expected" declarations. For instance, while + // + // namespace n + // + // can be none other than the beginning of a namespace declaration, JavaScript sees + // + // namespace + // n + // + // as the identifier 'namespace' on one line followed by the identifier 'n' on another. + // We need to look one token ahead to see if it permissible to try parsing a declaration. case SyntaxKind.DeclareKeyword: if (lookAhead(isFollowedByIdentifierOrKeywordOnSameLine) && getDeclarationFlags() & flags) { return parseDeclaration(); @@ -3997,19 +4024,6 @@ module ts { return parseDeclaration(); } break; - case SyntaxKind.ConstKeyword: - case SyntaxKind.EnumKeyword: - case SyntaxKind.ExportKeyword: - case SyntaxKind.ImportKeyword: - case SyntaxKind.InterfaceKeyword: - case SyntaxKind.PrivateKeyword: - case SyntaxKind.ProtectedKeyword: - case SyntaxKind.PublicKeyword: - case SyntaxKind.StaticKeyword: - if (getDeclarationFlags() & flags) { - return parseDeclaration(); - } - break; } return parseExpressionOrLabeledStatement(); } From 64a31e2e51e7911db411a6f22fa46896f23d7121 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 3 Jun 2015 13:51:53 -0700 Subject: [PATCH 08/16] Renamed functions, removed the duplicates found from renaming. --- src/compiler/parser.ts | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 914952d516..b430a27e2b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2688,7 +2688,7 @@ module ts { function nextTokenIsIdentifierOnSameLine() { nextToken(); - return !scanner.hasPrecedingLineBreak() && isIdentifier() + return !scanner.hasPrecedingLineBreak() && isIdentifier(); } function parseYieldExpression(): YieldExpression { @@ -4009,18 +4009,18 @@ module ts { // as the identifier 'namespace' on one line followed by the identifier 'n' on another. // We need to look one token ahead to see if it permissible to try parsing a declaration. case SyntaxKind.DeclareKeyword: - if (lookAhead(isFollowedByIdentifierOrKeywordOnSameLine) && getDeclarationFlags() & flags) { + if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine) && getDeclarationFlags() & flags) { return parseDeclaration(); } break; case SyntaxKind.ModuleKeyword: - if (lookAhead(isFollowedByIdentifierOrStringOnSameLine) && getDeclarationFlags() & flags) { + if (lookAhead(nextTokenIsIdentifierOrStringLiteralOnSameLine) && getDeclarationFlags() & flags) { return parseDeclaration(); } break; case SyntaxKind.NamespaceKeyword: case SyntaxKind.TypeKeyword: - if (lookAhead(isFollowedByIdentifierOnSameLine) && getDeclarationFlags() & flags) { + if (lookAhead(nextTokenIsIdentifierOnSameLine) && getDeclarationFlags() & flags) { return parseDeclaration(); } break; @@ -4070,21 +4070,11 @@ module ts { } } - function isFollowedByIdentifierOrKeywordOnSameLine() { - nextToken(); - return !scanner.hasPrecedingLineBreak() && isIdentifierOrKeyword(); - } - - function isFollowedByIdentifierOrStringOnSameLine() { + function nextTokenIsIdentifierOrStringLiteralOnSameLine() { nextToken(); return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token === SyntaxKind.StringLiteral); } - function isFollowedByIdentifierOnSameLine() { - nextToken(); - return !scanner.hasPrecedingLineBreak() && isIdentifier(); - } - function parseFunctionBlockOrSemicolon(isGenerator: boolean, diagnosticMessage?: DiagnosticMessage): Block { if (token !== SyntaxKind.OpenBraceToken && canParseSemicolon()) { parseSemicolon(); From 8c422af4bcebbc757b515880cac53d56bedc3d89 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 4 Jun 2015 13:49:47 -0700 Subject: [PATCH 09/16] Added tests for interfaces and tagged templates. --- .../taggedTemplateStringsWithTagNamedDeclare.ts | 6 ++++++ .../taggedTemplateStringsWithTagNamedDeclareES6.ts | 6 ++++++ .../asiPreventsParsingAsInterface01.ts | 6 ++++++ .../asiPreventsParsingAsInterface02.ts | 6 ++++++ .../asiPreventsParsingAsInterface03.ts | 8 ++++++++ .../asiPreventsParsingAsInterface04.ts | 7 +++++++ .../asiPreventsParsingAsInterface05.ts | 12 ++++++++++++ 7 files changed, 51 insertions(+) create mode 100644 tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclare.ts create mode 100644 tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclareES6.ts create mode 100644 tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface01.ts create mode 100644 tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface02.ts create mode 100644 tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface03.ts create mode 100644 tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface04.ts create mode 100644 tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface05.ts diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclare.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclare.ts new file mode 100644 index 0000000000..e769607f54 --- /dev/null +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclare.ts @@ -0,0 +1,6 @@ + + +function declare(x: any, ...ys: any[]) { +} + +declare `Hello ${0} world!`; \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclareES6.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclareES6.ts new file mode 100644 index 0000000000..c526d6110b --- /dev/null +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclareES6.ts @@ -0,0 +1,6 @@ +//@target: es6 + +function declare(x: any, ...ys: any[]) { +} + +declare `Hello ${0} world!`; \ No newline at end of file diff --git a/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface01.ts b/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface01.ts new file mode 100644 index 0000000000..2af52adade --- /dev/null +++ b/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface01.ts @@ -0,0 +1,6 @@ + +var interface: number, I: string; + +interface // This should be the identifier 'interface' +I // This should be the identifier 'I' +{} // This should be a block body \ No newline at end of file diff --git a/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface02.ts b/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface02.ts new file mode 100644 index 0000000000..e2cfa972f0 --- /dev/null +++ b/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface02.ts @@ -0,0 +1,6 @@ + +function f(interface: number, I: string) { + interface // This should be the identifier 'interface' + I // This should be the identifier 'I' + {} // This should be a block body +} \ No newline at end of file diff --git a/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface03.ts b/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface03.ts new file mode 100644 index 0000000000..5b93084b0d --- /dev/null +++ b/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface03.ts @@ -0,0 +1,8 @@ + +var interface: number, I: string; + +namespace n { + interface // This should be the identifier 'interface' + I // This should be the identifier 'I' + {} // This should be a block body +} \ No newline at end of file diff --git a/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface04.ts b/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface04.ts new file mode 100644 index 0000000000..3cafc549df --- /dev/null +++ b/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface04.ts @@ -0,0 +1,7 @@ + +var declare: boolean, interface: number, I: string; + +declare // This should be the identifier 'declare' +interface // This should be the identifier 'interface' +I // This should be the identifier 'I' +{} // This should be a block body \ No newline at end of file diff --git a/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface05.ts b/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface05.ts new file mode 100644 index 0000000000..1c7dd46de6 --- /dev/null +++ b/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface05.ts @@ -0,0 +1,12 @@ +"use strict" + +var interface: number; + +// 'interface' is a strict mode reserved word, and so it would be permissible +// to allow 'interface' and the name of the interface to be on separate lines; +// however, this complicates things, and so it is preferable to restrict interface +// declarations such that their identifier must follow 'interface' on the same line. + +interface // This should be the identifier 'interface' +I // This should be the identifier 'I' +{ } // This should be a block body \ No newline at end of file From 8af07ee0c0e4d8ea9e33889aa1038ae17dff13ef Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 4 Jun 2015 14:03:00 -0700 Subject: [PATCH 10/16] Accepted baselines. --- .../asiPreventsParsingAsInterface01.js | 10 ++++++++++ .../asiPreventsParsingAsInterface01.symbols | 11 +++++++++++ .../asiPreventsParsingAsInterface01.types | 11 +++++++++++ .../asiPreventsParsingAsInterface02.js | 11 +++++++++++ .../asiPreventsParsingAsInterface02.symbols | 13 +++++++++++++ .../asiPreventsParsingAsInterface02.types | 13 +++++++++++++ .../asiPreventsParsingAsInterface03.js | 12 ++++++++++++ .../asiPreventsParsingAsInterface03.symbols | 15 +++++++++++++++ .../asiPreventsParsingAsInterface03.types | 15 +++++++++++++++ .../asiPreventsParsingAsInterface04.js | 12 ++++++++++++ .../asiPreventsParsingAsInterface04.symbols | 15 +++++++++++++++ .../asiPreventsParsingAsInterface04.types | 15 +++++++++++++++ .../asiPreventsParsingAsInterface05.errors.txt | 18 ++++++++++++++++++ .../asiPreventsParsingAsInterface05.js | 17 +++++++++++++++++ ...taggedTemplateStringsWithTagNamedDeclare.js | 17 +++++++++++++++++ ...dTemplateStringsWithTagNamedDeclare.symbols | 12 ++++++++++++ ...gedTemplateStringsWithTagNamedDeclare.types | 15 +++++++++++++++ ...gedTemplateStringsWithTagNamedDeclareES6.js | 11 +++++++++++ ...mplateStringsWithTagNamedDeclareES6.symbols | 11 +++++++++++ ...TemplateStringsWithTagNamedDeclareES6.types | 14 ++++++++++++++ 20 files changed, 268 insertions(+) create mode 100644 tests/baselines/reference/asiPreventsParsingAsInterface01.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsInterface01.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsInterface01.types create mode 100644 tests/baselines/reference/asiPreventsParsingAsInterface02.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsInterface02.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsInterface02.types create mode 100644 tests/baselines/reference/asiPreventsParsingAsInterface03.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsInterface03.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsInterface03.types create mode 100644 tests/baselines/reference/asiPreventsParsingAsInterface04.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsInterface04.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsInterface04.types create mode 100644 tests/baselines/reference/asiPreventsParsingAsInterface05.errors.txt create mode 100644 tests/baselines/reference/asiPreventsParsingAsInterface05.js create mode 100644 tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclare.js create mode 100644 tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclare.symbols create mode 100644 tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclare.types create mode 100644 tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclareES6.js create mode 100644 tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclareES6.symbols create mode 100644 tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclareES6.types diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface01.js b/tests/baselines/reference/asiPreventsParsingAsInterface01.js new file mode 100644 index 0000000000..43692b6e19 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface01.js @@ -0,0 +1,10 @@ +//// [asiPreventsParsingAsInterface01.ts] + +var interface: number, I: string; + +interface // This should be the identifier 'interface' +I // This should be the identifier 'I' +{} // This should be a block body + +//// [asiPreventsParsingAsInterface01.js] +var interface, I; diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface01.symbols b/tests/baselines/reference/asiPreventsParsingAsInterface01.symbols new file mode 100644 index 0000000000..5973e99f67 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface01.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface01.ts === + +var interface: number, I: string; +>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface01.ts, 1, 3)) +>I : Symbol(I, Decl(asiPreventsParsingAsInterface01.ts, 1, 22), Decl(asiPreventsParsingAsInterface01.ts, 1, 33)) + +interface // This should be the identifier 'interface' +I // This should be the identifier 'I' +>I : Symbol(I, Decl(asiPreventsParsingAsInterface01.ts, 1, 22), Decl(asiPreventsParsingAsInterface01.ts, 1, 33)) + +{} // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface01.types b/tests/baselines/reference/asiPreventsParsingAsInterface01.types new file mode 100644 index 0000000000..d6f0e4bff8 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface01.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface01.ts === + +var interface: number, I: string; +>interface : number +>I : string + +interface // This should be the identifier 'interface' +I // This should be the identifier 'I' +>I : I + +{} // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface02.js b/tests/baselines/reference/asiPreventsParsingAsInterface02.js new file mode 100644 index 0000000000..f562126926 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface02.js @@ -0,0 +1,11 @@ +//// [asiPreventsParsingAsInterface02.ts] + +function f(interface: number, I: string) { + interface // This should be the identifier 'interface' + I // This should be the identifier 'I' + {} // This should be a block body +} + +//// [asiPreventsParsingAsInterface02.js] +function f(interface, I) { +} diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface02.symbols b/tests/baselines/reference/asiPreventsParsingAsInterface02.symbols new file mode 100644 index 0000000000..9f152e1bd0 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface02.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface02.ts === + +function f(interface: number, I: string) { +>f : Symbol(f, Decl(asiPreventsParsingAsInterface02.ts, 0, 0)) +>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface02.ts, 1, 11)) +>I : Symbol(I, Decl(asiPreventsParsingAsInterface02.ts, 1, 29), Decl(asiPreventsParsingAsInterface02.ts, 1, 42)) + + interface // This should be the identifier 'interface' + I // This should be the identifier 'I' +>I : Symbol(I, Decl(asiPreventsParsingAsInterface02.ts, 1, 29), Decl(asiPreventsParsingAsInterface02.ts, 1, 42)) + + {} // This should be a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface02.types b/tests/baselines/reference/asiPreventsParsingAsInterface02.types new file mode 100644 index 0000000000..ceb7c87ae2 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface02.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface02.ts === + +function f(interface: number, I: string) { +>f : (interface: number, I: string) => void +>interface : number +>I : string + + interface // This should be the identifier 'interface' + I // This should be the identifier 'I' +>I : I + + {} // This should be a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface03.js b/tests/baselines/reference/asiPreventsParsingAsInterface03.js new file mode 100644 index 0000000000..99dee27537 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface03.js @@ -0,0 +1,12 @@ +//// [asiPreventsParsingAsInterface03.ts] + +var interface: number, I: string; + +namespace n { + interface // This should be the identifier 'interface' + I // This should be the identifier 'I' + {} // This should be a block body +} + +//// [asiPreventsParsingAsInterface03.js] +var interface, I; diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface03.symbols b/tests/baselines/reference/asiPreventsParsingAsInterface03.symbols new file mode 100644 index 0000000000..f628543c00 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface03.symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface03.ts === + +var interface: number, I: string; +>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface03.ts, 1, 3)) +>I : Symbol(I, Decl(asiPreventsParsingAsInterface03.ts, 1, 22)) + +namespace n { +>n : Symbol(n, Decl(asiPreventsParsingAsInterface03.ts, 1, 33)) + + interface // This should be the identifier 'interface' + I // This should be the identifier 'I' +>I : Symbol(I, Decl(asiPreventsParsingAsInterface03.ts, 3, 13)) + + {} // This should be a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface03.types b/tests/baselines/reference/asiPreventsParsingAsInterface03.types new file mode 100644 index 0000000000..9087d816fa --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface03.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface03.ts === + +var interface: number, I: string; +>interface : number +>I : string + +namespace n { +>n : any + + interface // This should be the identifier 'interface' + I // This should be the identifier 'I' +>I : I + + {} // This should be a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface04.js b/tests/baselines/reference/asiPreventsParsingAsInterface04.js new file mode 100644 index 0000000000..5aced8231f --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface04.js @@ -0,0 +1,12 @@ +//// [asiPreventsParsingAsInterface04.ts] + +var declare: boolean, interface: number, I: string; + +declare // This should be the identifier 'declare' +interface // This should be the identifier 'interface' +I // This should be the identifier 'I' +{} // This should be a block body + +//// [asiPreventsParsingAsInterface04.js] +var declare, interface, I; +declare; // This should be the identifier 'declare' diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface04.symbols b/tests/baselines/reference/asiPreventsParsingAsInterface04.symbols new file mode 100644 index 0000000000..c60a680abe --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface04.symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface04.ts === + +var declare: boolean, interface: number, I: string; +>declare : Symbol(declare, Decl(asiPreventsParsingAsInterface04.ts, 1, 3)) +>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface04.ts, 1, 21)) +>I : Symbol(I, Decl(asiPreventsParsingAsInterface04.ts, 1, 40), Decl(asiPreventsParsingAsInterface04.ts, 3, 7)) + +declare // This should be the identifier 'declare' +>declare : Symbol(declare, Decl(asiPreventsParsingAsInterface04.ts, 1, 3)) + +interface // This should be the identifier 'interface' +I // This should be the identifier 'I' +>I : Symbol(I, Decl(asiPreventsParsingAsInterface04.ts, 1, 40), Decl(asiPreventsParsingAsInterface04.ts, 3, 7)) + +{} // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface04.types b/tests/baselines/reference/asiPreventsParsingAsInterface04.types new file mode 100644 index 0000000000..342ff15558 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface04.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface04.ts === + +var declare: boolean, interface: number, I: string; +>declare : boolean +>interface : number +>I : string + +declare // This should be the identifier 'declare' +>declare : boolean + +interface // This should be the identifier 'interface' +I // This should be the identifier 'I' +>I : I + +{} // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface05.errors.txt b/tests/baselines/reference/asiPreventsParsingAsInterface05.errors.txt new file mode 100644 index 0000000000..717ea86a0c --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface05.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface05.ts(3,5): error TS1212: Identifier expected. 'interface' is a reserved word in strict mode + + +==== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface05.ts (1 errors) ==== + "use strict" + + var interface: number; + ~~~~~~~~~ +!!! error TS1212: Identifier expected. 'interface' is a reserved word in strict mode + + // 'interface' is a strict mode reserved word, and so it would be permissible + // to allow 'interface' and the name of the interface to be on separate lines; + // however, this complicates things, and so it is preferable to restrict interface + // declarations such that their identifier must follow 'interface' on the same line. + + interface // This should be the identifier 'interface' + I // This should be the identifier 'I' + { } // This should be a block body \ No newline at end of file diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface05.js b/tests/baselines/reference/asiPreventsParsingAsInterface05.js new file mode 100644 index 0000000000..1e67795f1a --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface05.js @@ -0,0 +1,17 @@ +//// [asiPreventsParsingAsInterface05.ts] +"use strict" + +var interface: number; + +// 'interface' is a strict mode reserved word, and so it would be permissible +// to allow 'interface' and the name of the interface to be on separate lines; +// however, this complicates things, and so it is preferable to restrict interface +// declarations such that their identifier must follow 'interface' on the same line. + +interface // This should be the identifier 'interface' +I // This should be the identifier 'I' +{ } // This should be a block body + +//// [asiPreventsParsingAsInterface05.js] +"use strict"; +var interface; diff --git a/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclare.js b/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclare.js new file mode 100644 index 0000000000..1c25578af2 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclare.js @@ -0,0 +1,17 @@ +//// [taggedTemplateStringsWithTagNamedDeclare.ts] + + +function declare(x: any, ...ys: any[]) { +} + +declare `Hello ${0} world!`; + +//// [taggedTemplateStringsWithTagNamedDeclare.js] +function declare(x) { + var ys = []; + for (var _i = 1; _i < arguments.length; _i++) { + ys[_i - 1] = arguments[_i]; + } +} +(_a = ["Hello ", " world!"], _a.raw = ["Hello ", " world!"], declare(_a, 0)); +var _a; diff --git a/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclare.symbols b/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclare.symbols new file mode 100644 index 0000000000..ae73d532a0 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclare.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclare.ts === + + +function declare(x: any, ...ys: any[]) { +>declare : Symbol(declare, Decl(taggedTemplateStringsWithTagNamedDeclare.ts, 0, 0)) +>x : Symbol(x, Decl(taggedTemplateStringsWithTagNamedDeclare.ts, 2, 17)) +>ys : Symbol(ys, Decl(taggedTemplateStringsWithTagNamedDeclare.ts, 2, 24)) +} + +declare `Hello ${0} world!`; +>declare : Symbol(declare, Decl(taggedTemplateStringsWithTagNamedDeclare.ts, 0, 0)) + diff --git a/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclare.types b/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclare.types new file mode 100644 index 0000000000..d1f56f387d --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclare.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclare.ts === + + +function declare(x: any, ...ys: any[]) { +>declare : (x: any, ...ys: any[]) => void +>x : any +>ys : any[] +} + +declare `Hello ${0} world!`; +>declare `Hello ${0} world!` : void +>declare : (x: any, ...ys: any[]) => void +>`Hello ${0} world!` : string +>0 : number + diff --git a/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclareES6.js b/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclareES6.js new file mode 100644 index 0000000000..cd2833f383 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclareES6.js @@ -0,0 +1,11 @@ +//// [taggedTemplateStringsWithTagNamedDeclareES6.ts] + +function declare(x: any, ...ys: any[]) { +} + +declare `Hello ${0} world!`; + +//// [taggedTemplateStringsWithTagNamedDeclareES6.js] +function declare(x, ...ys) { +} +declare `Hello ${0} world!`; diff --git a/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclareES6.symbols b/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclareES6.symbols new file mode 100644 index 0000000000..960a12d235 --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclareES6.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclareES6.ts === + +function declare(x: any, ...ys: any[]) { +>declare : Symbol(declare, Decl(taggedTemplateStringsWithTagNamedDeclareES6.ts, 0, 0)) +>x : Symbol(x, Decl(taggedTemplateStringsWithTagNamedDeclareES6.ts, 1, 17)) +>ys : Symbol(ys, Decl(taggedTemplateStringsWithTagNamedDeclareES6.ts, 1, 24)) +} + +declare `Hello ${0} world!`; +>declare : Symbol(declare, Decl(taggedTemplateStringsWithTagNamedDeclareES6.ts, 0, 0)) + diff --git a/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclareES6.types b/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclareES6.types new file mode 100644 index 0000000000..e2274f82ff --- /dev/null +++ b/tests/baselines/reference/taggedTemplateStringsWithTagNamedDeclareES6.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclareES6.ts === + +function declare(x: any, ...ys: any[]) { +>declare : (x: any, ...ys: any[]) => void +>x : any +>ys : any[] +} + +declare `Hello ${0} world!`; +>declare `Hello ${0} world!` : void +>declare : (x: any, ...ys: any[]) => void +>`Hello ${0} world!` : string +>0 : number + From 047d3aef190b8ba4806571108e21d1f72829fa0d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 4 Jun 2015 14:37:22 -0700 Subject: [PATCH 11/16] Account for interfaces. --- src/compiler/parser.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b430a27e2b..87a13c6fbc 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3986,7 +3986,6 @@ module ts { case SyntaxKind.EnumKeyword: case SyntaxKind.ExportKeyword: case SyntaxKind.ImportKeyword: - case SyntaxKind.InterfaceKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.PublicKeyword: @@ -3996,8 +3995,8 @@ module ts { } break; - // 'declare', 'module', 'namespace', and 'type' are all legal JavaScript identifiers when ASI - // takes effect. In such cases, we cannot parse out the "expected" declarations. For instance, while + // 'declare', 'module', 'namespace', 'interface'* and 'type' are all legal JavaScript identifiers when + // ASI takes effect. In such cases, we cannot parse out the "expected" declarations. For instance, while // // namespace n // @@ -4008,6 +4007,14 @@ module ts { // // as the identifier 'namespace' on one line followed by the identifier 'n' on another. // We need to look one token ahead to see if it permissible to try parsing a declaration. + // + // *Note*: 'interface' is actually a strict mode reserved word. So while + // + // "use strict" + // interface + // I {} + // + // could be legal, it would add complexity for very little gain. case SyntaxKind.DeclareKeyword: if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine) && getDeclarationFlags() & flags) { return parseDeclaration(); @@ -4018,6 +4025,7 @@ module ts { return parseDeclaration(); } break; + case SyntaxKind.InterfaceKeyword: case SyntaxKind.NamespaceKeyword: case SyntaxKind.TypeKeyword: if (lookAhead(nextTokenIsIdentifierOnSameLine) && getDeclarationFlags() & flags) { @@ -4616,7 +4624,7 @@ module ts { function parseModuleBlock(): ModuleBlock { let node = createNode(SyntaxKind.ModuleBlock, scanner.getStartPos()); if (parseExpected(SyntaxKind.OpenBraceToken)) { - node.statements = parseList(ParsingContext.ModuleElements, /*checkForStrictMode*/false, parseModuleElement); + node.statements = parseList(ParsingContext.ModuleElements, /*checkForStrictMode*/ false, parseModuleElement); parseExpected(SyntaxKind.CloseBraceToken); } else { From 534105cfe57e58932a8310c6b432863547712817 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 4 Jun 2015 14:37:40 -0700 Subject: [PATCH 12/16] Accepted new baselines. --- .../reference/asiPreventsParsingAsInterface01.js | 3 +++ .../reference/asiPreventsParsingAsInterface01.symbols | 6 ++++-- .../reference/asiPreventsParsingAsInterface01.types | 4 +++- .../reference/asiPreventsParsingAsInterface02.js | 3 +++ .../reference/asiPreventsParsingAsInterface02.symbols | 6 ++++-- .../reference/asiPreventsParsingAsInterface02.types | 4 +++- .../reference/asiPreventsParsingAsInterface03.js | 6 ++++++ .../reference/asiPreventsParsingAsInterface03.symbols | 4 +++- .../reference/asiPreventsParsingAsInterface03.types | 6 ++++-- .../reference/asiPreventsParsingAsInterface04.js | 3 +++ .../reference/asiPreventsParsingAsInterface04.symbols | 6 ++++-- .../reference/asiPreventsParsingAsInterface04.types | 4 +++- .../reference/asiPreventsParsingAsInterface05.errors.txt | 8 +++++++- .../reference/asiPreventsParsingAsInterface05.js | 7 +++++++ .../interfacesWithPredefinedTypesAsNames.errors.txt | 9 ++++++--- .../reference/interfacesWithPredefinedTypesAsNames.js | 1 + 16 files changed, 64 insertions(+), 16 deletions(-) diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface01.js b/tests/baselines/reference/asiPreventsParsingAsInterface01.js index 43692b6e19..024ad54371 100644 --- a/tests/baselines/reference/asiPreventsParsingAsInterface01.js +++ b/tests/baselines/reference/asiPreventsParsingAsInterface01.js @@ -8,3 +8,6 @@ I // This should be the identifier 'I' //// [asiPreventsParsingAsInterface01.js] var interface, I; +interface; // This should be the identifier 'interface' +I; // This should be the identifier 'I' +{ } // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface01.symbols b/tests/baselines/reference/asiPreventsParsingAsInterface01.symbols index 5973e99f67..d92c13e8ce 100644 --- a/tests/baselines/reference/asiPreventsParsingAsInterface01.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsInterface01.symbols @@ -2,10 +2,12 @@ var interface: number, I: string; >interface : Symbol(interface, Decl(asiPreventsParsingAsInterface01.ts, 1, 3)) ->I : Symbol(I, Decl(asiPreventsParsingAsInterface01.ts, 1, 22), Decl(asiPreventsParsingAsInterface01.ts, 1, 33)) +>I : Symbol(I, Decl(asiPreventsParsingAsInterface01.ts, 1, 22)) interface // This should be the identifier 'interface' +>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface01.ts, 1, 3)) + I // This should be the identifier 'I' ->I : Symbol(I, Decl(asiPreventsParsingAsInterface01.ts, 1, 22), Decl(asiPreventsParsingAsInterface01.ts, 1, 33)) +>I : Symbol(I, Decl(asiPreventsParsingAsInterface01.ts, 1, 22)) {} // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface01.types b/tests/baselines/reference/asiPreventsParsingAsInterface01.types index d6f0e4bff8..03c1b9fc41 100644 --- a/tests/baselines/reference/asiPreventsParsingAsInterface01.types +++ b/tests/baselines/reference/asiPreventsParsingAsInterface01.types @@ -5,7 +5,9 @@ var interface: number, I: string; >I : string interface // This should be the identifier 'interface' +>interface : number + I // This should be the identifier 'I' ->I : I +>I : string {} // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface02.js b/tests/baselines/reference/asiPreventsParsingAsInterface02.js index f562126926..0ea0421550 100644 --- a/tests/baselines/reference/asiPreventsParsingAsInterface02.js +++ b/tests/baselines/reference/asiPreventsParsingAsInterface02.js @@ -8,4 +8,7 @@ function f(interface: number, I: string) { //// [asiPreventsParsingAsInterface02.js] function f(interface, I) { + interface; // This should be the identifier 'interface' + I; // This should be the identifier 'I' + { } // This should be a block body } diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface02.symbols b/tests/baselines/reference/asiPreventsParsingAsInterface02.symbols index 9f152e1bd0..e1e4febe38 100644 --- a/tests/baselines/reference/asiPreventsParsingAsInterface02.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsInterface02.symbols @@ -3,11 +3,13 @@ function f(interface: number, I: string) { >f : Symbol(f, Decl(asiPreventsParsingAsInterface02.ts, 0, 0)) >interface : Symbol(interface, Decl(asiPreventsParsingAsInterface02.ts, 1, 11)) ->I : Symbol(I, Decl(asiPreventsParsingAsInterface02.ts, 1, 29), Decl(asiPreventsParsingAsInterface02.ts, 1, 42)) +>I : Symbol(I, Decl(asiPreventsParsingAsInterface02.ts, 1, 29)) interface // This should be the identifier 'interface' +>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface02.ts, 1, 11)) + I // This should be the identifier 'I' ->I : Symbol(I, Decl(asiPreventsParsingAsInterface02.ts, 1, 29), Decl(asiPreventsParsingAsInterface02.ts, 1, 42)) +>I : Symbol(I, Decl(asiPreventsParsingAsInterface02.ts, 1, 29)) {} // This should be a block body } diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface02.types b/tests/baselines/reference/asiPreventsParsingAsInterface02.types index ceb7c87ae2..7989cc810a 100644 --- a/tests/baselines/reference/asiPreventsParsingAsInterface02.types +++ b/tests/baselines/reference/asiPreventsParsingAsInterface02.types @@ -6,8 +6,10 @@ function f(interface: number, I: string) { >I : string interface // This should be the identifier 'interface' +>interface : number + I // This should be the identifier 'I' ->I : I +>I : string {} // This should be a block body } diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface03.js b/tests/baselines/reference/asiPreventsParsingAsInterface03.js index 99dee27537..3b3c836f7f 100644 --- a/tests/baselines/reference/asiPreventsParsingAsInterface03.js +++ b/tests/baselines/reference/asiPreventsParsingAsInterface03.js @@ -10,3 +10,9 @@ namespace n { //// [asiPreventsParsingAsInterface03.js] var interface, I; +var n; +(function (n) { + interface; // This should be the identifier 'interface' + I; // This should be the identifier 'I' + { } // This should be a block body +})(n || (n = {})); diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface03.symbols b/tests/baselines/reference/asiPreventsParsingAsInterface03.symbols index f628543c00..e8c95cf124 100644 --- a/tests/baselines/reference/asiPreventsParsingAsInterface03.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsInterface03.symbols @@ -8,8 +8,10 @@ namespace n { >n : Symbol(n, Decl(asiPreventsParsingAsInterface03.ts, 1, 33)) interface // This should be the identifier 'interface' +>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface03.ts, 1, 3)) + I // This should be the identifier 'I' ->I : Symbol(I, Decl(asiPreventsParsingAsInterface03.ts, 3, 13)) +>I : Symbol(I, Decl(asiPreventsParsingAsInterface03.ts, 1, 22)) {} // This should be a block body } diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface03.types b/tests/baselines/reference/asiPreventsParsingAsInterface03.types index 9087d816fa..a58d502fc2 100644 --- a/tests/baselines/reference/asiPreventsParsingAsInterface03.types +++ b/tests/baselines/reference/asiPreventsParsingAsInterface03.types @@ -5,11 +5,13 @@ var interface: number, I: string; >I : string namespace n { ->n : any +>n : typeof n interface // This should be the identifier 'interface' +>interface : number + I // This should be the identifier 'I' ->I : I +>I : string {} // This should be a block body } diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface04.js b/tests/baselines/reference/asiPreventsParsingAsInterface04.js index 5aced8231f..1700636e52 100644 --- a/tests/baselines/reference/asiPreventsParsingAsInterface04.js +++ b/tests/baselines/reference/asiPreventsParsingAsInterface04.js @@ -10,3 +10,6 @@ I // This should be the identifier 'I' //// [asiPreventsParsingAsInterface04.js] var declare, interface, I; declare; // This should be the identifier 'declare' +interface; // This should be the identifier 'interface' +I; // This should be the identifier 'I' +{ } // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface04.symbols b/tests/baselines/reference/asiPreventsParsingAsInterface04.symbols index c60a680abe..094411ebed 100644 --- a/tests/baselines/reference/asiPreventsParsingAsInterface04.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsInterface04.symbols @@ -3,13 +3,15 @@ var declare: boolean, interface: number, I: string; >declare : Symbol(declare, Decl(asiPreventsParsingAsInterface04.ts, 1, 3)) >interface : Symbol(interface, Decl(asiPreventsParsingAsInterface04.ts, 1, 21)) ->I : Symbol(I, Decl(asiPreventsParsingAsInterface04.ts, 1, 40), Decl(asiPreventsParsingAsInterface04.ts, 3, 7)) +>I : Symbol(I, Decl(asiPreventsParsingAsInterface04.ts, 1, 40)) declare // This should be the identifier 'declare' >declare : Symbol(declare, Decl(asiPreventsParsingAsInterface04.ts, 1, 3)) interface // This should be the identifier 'interface' +>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface04.ts, 1, 21)) + I // This should be the identifier 'I' ->I : Symbol(I, Decl(asiPreventsParsingAsInterface04.ts, 1, 40), Decl(asiPreventsParsingAsInterface04.ts, 3, 7)) +>I : Symbol(I, Decl(asiPreventsParsingAsInterface04.ts, 1, 40)) {} // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface04.types b/tests/baselines/reference/asiPreventsParsingAsInterface04.types index 342ff15558..f6d29749ae 100644 --- a/tests/baselines/reference/asiPreventsParsingAsInterface04.types +++ b/tests/baselines/reference/asiPreventsParsingAsInterface04.types @@ -9,7 +9,9 @@ declare // This should be the identifier 'declare' >declare : boolean interface // This should be the identifier 'interface' +>interface : number + I // This should be the identifier 'I' ->I : I +>I : string {} // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface05.errors.txt b/tests/baselines/reference/asiPreventsParsingAsInterface05.errors.txt index 717ea86a0c..e070305fdf 100644 --- a/tests/baselines/reference/asiPreventsParsingAsInterface05.errors.txt +++ b/tests/baselines/reference/asiPreventsParsingAsInterface05.errors.txt @@ -1,7 +1,9 @@ tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface05.ts(3,5): error TS1212: Identifier expected. 'interface' is a reserved word in strict mode +tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface05.ts(10,1): error TS1212: Identifier expected. 'interface' is a reserved word in strict mode +tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface05.ts(11,1): error TS2304: Cannot find name 'I'. -==== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface05.ts (1 errors) ==== +==== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface05.ts (3 errors) ==== "use strict" var interface: number; @@ -14,5 +16,9 @@ tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInt // declarations such that their identifier must follow 'interface' on the same line. interface // This should be the identifier 'interface' + ~~~~~~~~~ +!!! error TS1212: Identifier expected. 'interface' is a reserved word in strict mode I // This should be the identifier 'I' + ~ +!!! error TS2304: Cannot find name 'I'. { } // This should be a block body \ No newline at end of file diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface05.js b/tests/baselines/reference/asiPreventsParsingAsInterface05.js index 1e67795f1a..85c19be447 100644 --- a/tests/baselines/reference/asiPreventsParsingAsInterface05.js +++ b/tests/baselines/reference/asiPreventsParsingAsInterface05.js @@ -15,3 +15,10 @@ I // This should be the identifier 'I' //// [asiPreventsParsingAsInterface05.js] "use strict"; var interface; +// 'interface' is a strict mode reserved word, and so it would be permissible +// to allow 'interface' and the name of the interface to be on separate lines; +// however, this complicates things, and so it is preferable to restrict interface +// declarations such that their identifier must follow 'interface' on the same line. +interface; // This should be the identifier 'interface' +I; // This should be the identifier 'I' +{ } // This should be a block body diff --git a/tests/baselines/reference/interfacesWithPredefinedTypesAsNames.errors.txt b/tests/baselines/reference/interfacesWithPredefinedTypesAsNames.errors.txt index 91cd267b59..902e4b448b 100644 --- a/tests/baselines/reference/interfacesWithPredefinedTypesAsNames.errors.txt +++ b/tests/baselines/reference/interfacesWithPredefinedTypesAsNames.errors.txt @@ -2,10 +2,11 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefine tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts(2,11): error TS2427: Interface name cannot be 'number' tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts(3,11): error TS2427: Interface name cannot be 'string' tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts(4,11): error TS2427: Interface name cannot be 'boolean' -tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts(5,11): error TS1003: Identifier expected. +tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts(5,1): error TS2304: Cannot find name 'interface'. +tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts(5,11): error TS1005: ';' expected. -==== tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts (5 errors) ==== +==== tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts (6 errors) ==== interface any { } ~~~ !!! error TS2427: Interface name cannot be 'any' @@ -19,5 +20,7 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefine ~~~~~~~ !!! error TS2427: Interface name cannot be 'boolean' interface void {} + ~~~~~~~~~ +!!! error TS2304: Cannot find name 'interface'. ~~~~ -!!! error TS1003: Identifier expected. \ No newline at end of file +!!! error TS1005: ';' expected. \ No newline at end of file diff --git a/tests/baselines/reference/interfacesWithPredefinedTypesAsNames.js b/tests/baselines/reference/interfacesWithPredefinedTypesAsNames.js index b79dfc12a0..ca186b1cef 100644 --- a/tests/baselines/reference/interfacesWithPredefinedTypesAsNames.js +++ b/tests/baselines/reference/interfacesWithPredefinedTypesAsNames.js @@ -6,4 +6,5 @@ interface boolean { } interface void {} //// [interfacesWithPredefinedTypesAsNames.js] +interface; void {}; From 10861b16487e785a1a05b92ab28429d0b11ca007 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 4 Jun 2015 16:29:12 -0700 Subject: [PATCH 13/16] Amended comment. --- src/compiler/parser.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 87a13c6fbc..467be939c9 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3995,12 +3995,13 @@ module ts { } break; - // 'declare', 'module', 'namespace', 'interface'* and 'type' are all legal JavaScript identifiers when - // ASI takes effect. In such cases, we cannot parse out the "expected" declarations. For instance, while + // 'declare', 'module', 'namespace', 'interface'* and 'type' are all legal JavaScript identifiers; + // however, an identifier cannot be followed by another identifier on the same line. This is what we + // count on to parse out the respective declarations. For instance, we exploit this to say that // // namespace n // - // can be none other than the beginning of a namespace declaration, JavaScript sees + // can be none other than the beginning of a namespace declaration, but need to respect that JavaScript sees // // namespace // n From aef9edf0148896848712525da81d4e4b77bd4941 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 4 Jun 2015 17:40:03 -0700 Subject: [PATCH 14/16] Added test regarding 'declare' keyword as beginning of statement expression. --- .../declareIdentifierAsBeginningOfStatementExpression01.ts | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tests/cases/compiler/declareIdentifierAsBeginningOfStatementExpression01.ts diff --git a/tests/cases/compiler/declareIdentifierAsBeginningOfStatementExpression01.ts b/tests/cases/compiler/declareIdentifierAsBeginningOfStatementExpression01.ts new file mode 100644 index 0000000000..7c0697c627 --- /dev/null +++ b/tests/cases/compiler/declareIdentifierAsBeginningOfStatementExpression01.ts @@ -0,0 +1,6 @@ +class C { +} + +var declare: any; + +declare instanceof C; \ No newline at end of file From 18bd849ac7d981f2d36f6785fe158c0106446036 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 4 Jun 2015 17:45:04 -0700 Subject: [PATCH 15/16] Accepted baselines. --- ...entifierAsBeginningOfStatementExpression01.js | 16 ++++++++++++++++ ...ierAsBeginningOfStatementExpression01.symbols | 12 ++++++++++++ ...ifierAsBeginningOfStatementExpression01.types | 13 +++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.js create mode 100644 tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.symbols create mode 100644 tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.types diff --git a/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.js b/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.js new file mode 100644 index 0000000000..047b9b7671 --- /dev/null +++ b/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.js @@ -0,0 +1,16 @@ +//// [declareIdentifierAsBeginningOfStatementExpression01.ts] +class C { +} + +var declare: any; + +declare instanceof C; + +//// [declareIdentifierAsBeginningOfStatementExpression01.js] +var C = (function () { + function C() { + } + return C; +})(); +var declare; +declare instanceof C; diff --git a/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.symbols b/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.symbols new file mode 100644 index 0000000000..d4ef7378b0 --- /dev/null +++ b/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/declareIdentifierAsBeginningOfStatementExpression01.ts === +class C { +>C : Symbol(C, Decl(declareIdentifierAsBeginningOfStatementExpression01.ts, 0, 0)) +} + +var declare: any; +>declare : Symbol(declare, Decl(declareIdentifierAsBeginningOfStatementExpression01.ts, 3, 3)) + +declare instanceof C; +>declare : Symbol(declare, Decl(declareIdentifierAsBeginningOfStatementExpression01.ts, 3, 3)) +>C : Symbol(C, Decl(declareIdentifierAsBeginningOfStatementExpression01.ts, 0, 0)) + diff --git a/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.types b/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.types new file mode 100644 index 0000000000..2fad2eda16 --- /dev/null +++ b/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/declareIdentifierAsBeginningOfStatementExpression01.ts === +class C { +>C : C +} + +var declare: any; +>declare : any + +declare instanceof C; +>declare instanceof C : boolean +>declare : any +>C : typeof C + From 3d9293e0de1737bc61a225181320bff33f5fbe99 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 4 Jun 2015 18:08:11 -0700 Subject: [PATCH 16/16] Moved lookahead logic into 'getDeclarationFlags'. --- src/compiler/parser.ts | 79 +++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 43 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 467be939c9..55ba369bf0 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3811,14 +3811,42 @@ module ts { case SyntaxKind.ClassKeyword: case SyntaxKind.EnumKeyword: return StatementFlags.Statement; + + // 'declare', 'module', 'namespace', 'interface'* and 'type' are all legal JavaScript identifiers; + // however, an identifier cannot be followed by another identifier on the same line. This is what we + // count on to parse out the respective declarations. For instance, we exploit this to say that + // + // namespace n + // + // can be none other than the beginning of a namespace declaration, but need to respect that JavaScript sees + // + // namespace + // n + // + // as the identifier 'namespace' on one line followed by the identifier 'n' on another. + // We need to look one token ahead to see if it permissible to try parsing a declaration. + // + // *Note*: 'interface' is actually a strict mode reserved word. So while + // + // "use strict" + // interface + // I {} + // + // could be legal, it would add complexity for very little gain. case SyntaxKind.InterfaceKeyword: case SyntaxKind.TypeKeyword: - nextToken(); - return isIdentifierOrKeyword() ? StatementFlags.Statement : StatementFlags.None; + return nextTokenIsIdentifierOnSameLine() ? StatementFlags.Statement : StatementFlags.None; case SyntaxKind.ModuleKeyword: case SyntaxKind.NamespaceKeyword: + return nextTokenIsIdentifierOrStringLiteralOnSameLine() ? StatementFlags.ModuleElement : StatementFlags.None; + case SyntaxKind.DeclareKeyword: nextToken(); - return isIdentifierOrKeyword() || token === SyntaxKind.StringLiteral ? StatementFlags.ModuleElement : StatementFlags.None; + // ASI takes effect for this modifier. + if (scanner.hasPrecedingLineBreak()) { + return StatementFlags.None; + } + continue; + case SyntaxKind.ImportKeyword: nextToken(); return token === SyntaxKind.StringLiteral || token === SyntaxKind.AsteriskToken || @@ -3831,7 +3859,6 @@ module ts { return StatementFlags.ModuleElement; } continue; - case SyntaxKind.DeclareKeyword: case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: @@ -3982,6 +4009,11 @@ module ts { case SyntaxKind.AtToken: return parseDeclaration(); + case SyntaxKind.InterfaceKeyword: + case SyntaxKind.TypeKeyword: + case SyntaxKind.ModuleKeyword: + case SyntaxKind.NamespaceKeyword: + case SyntaxKind.DeclareKeyword: case SyntaxKind.ConstKeyword: case SyntaxKind.EnumKeyword: case SyntaxKind.ExportKeyword: @@ -3994,45 +4026,6 @@ module ts { return parseDeclaration(); } break; - - // 'declare', 'module', 'namespace', 'interface'* and 'type' are all legal JavaScript identifiers; - // however, an identifier cannot be followed by another identifier on the same line. This is what we - // count on to parse out the respective declarations. For instance, we exploit this to say that - // - // namespace n - // - // can be none other than the beginning of a namespace declaration, but need to respect that JavaScript sees - // - // namespace - // n - // - // as the identifier 'namespace' on one line followed by the identifier 'n' on another. - // We need to look one token ahead to see if it permissible to try parsing a declaration. - // - // *Note*: 'interface' is actually a strict mode reserved word. So while - // - // "use strict" - // interface - // I {} - // - // could be legal, it would add complexity for very little gain. - case SyntaxKind.DeclareKeyword: - if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine) && getDeclarationFlags() & flags) { - return parseDeclaration(); - } - break; - case SyntaxKind.ModuleKeyword: - if (lookAhead(nextTokenIsIdentifierOrStringLiteralOnSameLine) && getDeclarationFlags() & flags) { - return parseDeclaration(); - } - break; - case SyntaxKind.InterfaceKeyword: - case SyntaxKind.NamespaceKeyword: - case SyntaxKind.TypeKeyword: - if (lookAhead(nextTokenIsIdentifierOnSameLine) && getDeclarationFlags() & flags) { - return parseDeclaration(); - } - break; } return parseExpressionOrLabeledStatement(); }