Merge pull request #3365 from Microsoft/painInTheASI

Parse namespaces/types aliases/interfaces/ambient declarations only when they cannot be legal JS
This commit is contained in:
Daniel Rosenwasser 2015-06-08 10:27:15 -07:00
commit 6b77c24753
74 changed files with 1029 additions and 26 deletions

View file

@ -1816,7 +1816,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 <Identifier>createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentToken*/ true, Diagnostics.Identifier_expected);
}
}
@ -2686,7 +2686,7 @@ module ts {
function nextTokenIsIdentifierOnSameLine() {
nextToken();
return !scanner.hasPrecedingLineBreak() && isIdentifier()
return !scanner.hasPrecedingLineBreak() && isIdentifier();
}
function parseYieldExpression(): YieldExpression {
@ -3809,14 +3809,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 ||
@ -3829,7 +3857,6 @@ module ts {
return StatementFlags.ModuleElement;
}
continue;
case SyntaxKind.DeclareKeyword:
case SyntaxKind.PublicKeyword:
case SyntaxKind.PrivateKeyword:
case SyntaxKind.ProtectedKeyword:
@ -3971,7 +3998,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();
@ -3979,19 +4006,20 @@ module ts {
return parseDebuggerStatement();
case SyntaxKind.AtToken:
return parseDeclaration();
case SyntaxKind.ConstKeyword:
case SyntaxKind.InterfaceKeyword:
case SyntaxKind.TypeKeyword:
case SyntaxKind.ModuleKeyword:
case SyntaxKind.NamespaceKeyword:
case SyntaxKind.DeclareKeyword:
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();
}
@ -4042,6 +4070,11 @@ module ts {
}
}
function nextTokenIsIdentifierOrStringLiteralOnSameLine() {
nextToken();
return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token === SyntaxKind.StringLiteral);
}
function parseFunctionBlockOrSemicolon(isGenerator: boolean, diagnosticMessage?: DiagnosticMessage): Block {
if (token !== SyntaxKind.OpenBraceToken && canParseSemicolon()) {
parseSemicolon();
@ -4583,7 +4616,7 @@ module ts {
function parseModuleBlock(): ModuleBlock {
let node = <ModuleBlock>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 {

View file

@ -0,0 +1,17 @@
//// [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;
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

View file

@ -0,0 +1,16 @@
=== 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'
>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

View file

@ -0,0 +1,18 @@
=== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule01.ts ===
var declare: number;
>declare : number
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

View file

@ -0,0 +1,22 @@
//// [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;
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 = {}));

View file

@ -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
}

View file

@ -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
}

View file

@ -0,0 +1,13 @@
//// [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;
interface; // This should be the identifier 'interface'
I; // This should be the identifier 'I'
{ } // This should be a block body

View file

@ -0,0 +1,13 @@
=== 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))
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))
{} // This should be a block body

View file

@ -0,0 +1,13 @@
=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface01.ts ===
var interface: number, I: string;
>interface : number
>I : string
interface // This should be the identifier 'interface'
>interface : number
I // This should be the identifier 'I'
>I : string
{} // This should be a block body

View file

@ -0,0 +1,14 @@
//// [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) {
interface; // This should be the identifier 'interface'
I; // This should be the identifier 'I'
{ } // This should be a block body
}

View file

@ -0,0 +1,15 @@
=== 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))
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))
{} // This should be a block body
}

View file

@ -0,0 +1,15 @@
=== 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'
>interface : number
I // This should be the identifier 'I'
>I : string
{} // This should be a block body
}

View file

@ -0,0 +1,18 @@
//// [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;
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 = {}));

View file

@ -0,0 +1,17 @@
=== 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'
>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface03.ts, 1, 3))
I // This should be the identifier 'I'
>I : Symbol(I, Decl(asiPreventsParsingAsInterface03.ts, 1, 22))
{} // This should be a block body
}

View file

@ -0,0 +1,17 @@
=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface03.ts ===
var interface: number, I: string;
>interface : number
>I : string
namespace n {
>n : typeof n
interface // This should be the identifier 'interface'
>interface : number
I // This should be the identifier 'I'
>I : string
{} // This should be a block body
}

View file

@ -0,0 +1,15 @@
//// [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'
interface; // This should be the identifier 'interface'
I; // This should be the identifier 'I'
{ } // This should be a block body

View file

@ -0,0 +1,17 @@
=== 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))
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))
{} // This should be a block body

View file

@ -0,0 +1,17 @@
=== 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'
>interface : number
I // This should be the identifier 'I'
>I : string
{} // This should be a block body

View file

@ -0,0 +1,24 @@
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 (3 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'
~~~~~~~~~
!!! 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

View file

@ -0,0 +1,24 @@
//// [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;
// '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

View file

@ -0,0 +1,15 @@
//// [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;
namespace; // this is the identifier 'namespace'
n; // this is the identifier 'n'
{ } // this is a block body

View file

@ -0,0 +1,15 @@
=== 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))
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))
{ } // this is a block body

View file

@ -0,0 +1,15 @@
=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace01.ts ===
var namespace: number;
>namespace : number
var n: string;
>n : string
namespace // this is the identifier 'namespace'
>namespace : number
n // this is the identifier 'n'
>n : string
{ } // this is a block body

View file

@ -0,0 +1,15 @@
//// [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;
module; // this is the identifier 'namespace'
m; // this is the identifier 'm'
{ } // this is a block body

View file

@ -0,0 +1,15 @@
=== 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))
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))
{ } // this is a block body

View file

@ -0,0 +1,15 @@
=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace02.ts ===
var module: number;
>module : number
var m: string;
>m : string
module // this is the identifier 'namespace'
>module : number
m // this is the identifier 'm'
>m : string
{ } // this is a block body

View file

@ -0,0 +1,20 @@
//// [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;
var container;
(function (container) {
namespace; // this is the identifier 'namespace'
n; // this is the identifier 'n'
{ } // this is a block body
})(container || (container = {}));

View file

@ -0,0 +1,19 @@
=== 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'
>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace03.ts, 1, 3))
n // this is the identifier 'n'
>n : Symbol(n, Decl(asiPreventsParsingAsNamespace03.ts, 2, 3))
{ } // this is a block body
}

View file

@ -0,0 +1,19 @@
=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace03.ts ===
var namespace: number;
>namespace : number
var n: string;
>n : string
namespace container {
>container : typeof container
namespace // this is the identifier 'namespace'
>namespace : number
n // this is the identifier 'n'
>n : string
{ } // this is a block body
}

View file

@ -0,0 +1,8 @@
//// [asiPreventsParsingAsNamespace04.ts]
let module = 10;
module in {}
//// [asiPreventsParsingAsNamespace04.js]
var module = 10;
module in {};

View file

@ -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))

View file

@ -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
>{} : {}

View file

@ -0,0 +1,25 @@
//// [asiPreventsParsingAsNamespace05.ts]
let namespace = 10;
namespace a.b {
export let c = 20;
}
namespace
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;
{
}

View file

@ -0,0 +1,24 @@
=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05.ts ===
let namespace = 10;
>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace05.ts, 1, 3))
namespace a.b {
>a : Symbol(a, Decl(asiPreventsParsingAsNamespace05.ts, 1, 19))
>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))
{
}

View file

@ -0,0 +1,26 @@
=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05.ts ===
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.b.c : number
>a.b : typeof a.b
>a : typeof a
>b : typeof a.b
>c : number
{
}

View file

@ -0,0 +1,15 @@
//// [asiPreventsParsingAsTypeAlias01.ts]
var type;
var string;
var Foo;
type
Foo = string;
//// [asiPreventsParsingAsTypeAlias01.js]
var type;
var string;
var Foo;
type;
Foo = string;

View file

@ -0,0 +1,18 @@
=== 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))
type
>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))

View file

@ -0,0 +1,19 @@
=== tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias01.ts ===
var type;
>type : any
var string;
>string : any
var Foo;
>Foo : any
type
>type : any
Foo = string;
>Foo = string : any
>Foo : any
>string : any

View file

@ -0,0 +1,20 @@
//// [asiPreventsParsingAsTypeAlias02.ts]
var type;
var string;
var Foo;
namespace container {
type
Foo = string;
}
//// [asiPreventsParsingAsTypeAlias02.js]
var type;
var string;
var Foo;
var container;
(function (container) {
type;
Foo = string;
})(container || (container = {}));

View file

@ -0,0 +1,21 @@
=== 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
>type : Symbol(type, Decl(asiPreventsParsingAsTypeAlias02.ts, 1, 3))
Foo = string;
>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias02.ts, 3, 3))
>string : Symbol(string, Decl(asiPreventsParsingAsTypeAlias02.ts, 2, 3))
}

View file

@ -0,0 +1,22 @@
=== tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias02.ts ===
var type;
>type : any
var string;
>string : any
var Foo;
>Foo : any
namespace container {
>container : typeof container
type
>type : any
Foo = string;
>Foo = string : any
>Foo : any
>string : any
}

View file

@ -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;

View file

@ -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))

View file

@ -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

View file

@ -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.
!!! error TS1005: ';' expected.

View file

@ -6,4 +6,5 @@ interface boolean { }
interface void {}
//// [interfacesWithPredefinedTypesAsNames.js]
interface;
void {};

View file

@ -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'.

View file

@ -7,4 +7,6 @@ type string = I;
type void = I;
//// [reservedNamesInAliases.js]
type;
void ;
I;

View file

@ -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)'.

View file

@ -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;

View file

@ -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;

View file

@ -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))

View file

@ -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

View file

@ -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!`;

View file

@ -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))

View file

@ -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

View file

@ -0,0 +1,6 @@
class C {
}
var declare: any;
declare instanceof C;

View file

@ -0,0 +1,6 @@

function declare(x: any, ...ys: any[]) {
}
declare `Hello ${0} world!`;

View file

@ -0,0 +1,6 @@
//@target: es6
function declare(x: any, ...ys: any[]) {
}
declare `Hello ${0} world!`;

View file

@ -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

View file

@ -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
}

View file

@ -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

View file

@ -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
}

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
}

View file

@ -0,0 +1,3 @@
let module = 10;
module in {}

View file

@ -0,0 +1,10 @@
let namespace = 10;
namespace a.b {
export let c = 20;
}
namespace
a.b.c
{
}

View file

@ -0,0 +1,7 @@
var type;
var string;
var Foo;
type
Foo = string;

View file

@ -0,0 +1,9 @@
var type;
var string;
var Foo;
namespace container {
type
Foo = string;
}