diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9129a606f8..4d61944751 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -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 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 = 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 { diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js new file mode 100644 index 0000000000..caf90acae5 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js @@ -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 diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols new file mode 100644 index 0000000000..c35432b7ec --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols @@ -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 diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types new file mode 100644 index 0000000000..3e6aade9a2 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types @@ -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 diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js new file mode 100644 index 0000000000..20e2693ba7 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js @@ -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 = {})); 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/asiPreventsParsingAsInterface01.js b/tests/baselines/reference/asiPreventsParsingAsInterface01.js new file mode 100644 index 0000000000..024ad54371 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface01.js @@ -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 diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface01.symbols b/tests/baselines/reference/asiPreventsParsingAsInterface01.symbols new file mode 100644 index 0000000000..d92c13e8ce --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface01.symbols @@ -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 diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface01.types b/tests/baselines/reference/asiPreventsParsingAsInterface01.types new file mode 100644 index 0000000000..03c1b9fc41 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface01.types @@ -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 diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface02.js b/tests/baselines/reference/asiPreventsParsingAsInterface02.js new file mode 100644 index 0000000000..0ea0421550 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface02.js @@ -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 +} diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface02.symbols b/tests/baselines/reference/asiPreventsParsingAsInterface02.symbols new file mode 100644 index 0000000000..e1e4febe38 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface02.symbols @@ -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 +} diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface02.types b/tests/baselines/reference/asiPreventsParsingAsInterface02.types new file mode 100644 index 0000000000..7989cc810a --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface02.types @@ -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 +} diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface03.js b/tests/baselines/reference/asiPreventsParsingAsInterface03.js new file mode 100644 index 0000000000..3b3c836f7f --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface03.js @@ -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 = {})); diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface03.symbols b/tests/baselines/reference/asiPreventsParsingAsInterface03.symbols new file mode 100644 index 0000000000..e8c95cf124 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface03.symbols @@ -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 +} diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface03.types b/tests/baselines/reference/asiPreventsParsingAsInterface03.types new file mode 100644 index 0000000000..a58d502fc2 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface03.types @@ -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 +} diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface04.js b/tests/baselines/reference/asiPreventsParsingAsInterface04.js new file mode 100644 index 0000000000..1700636e52 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface04.js @@ -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 diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface04.symbols b/tests/baselines/reference/asiPreventsParsingAsInterface04.symbols new file mode 100644 index 0000000000..094411ebed --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface04.symbols @@ -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 diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface04.types b/tests/baselines/reference/asiPreventsParsingAsInterface04.types new file mode 100644 index 0000000000..f6d29749ae --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface04.types @@ -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 diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface05.errors.txt b/tests/baselines/reference/asiPreventsParsingAsInterface05.errors.txt new file mode 100644 index 0000000000..e070305fdf --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface05.errors.txt @@ -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 \ 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..85c19be447 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface05.js @@ -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 diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.js b/tests/baselines/reference/asiPreventsParsingAsNamespace01.js new file mode 100644 index 0000000000..282d9dd1c7 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.js @@ -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 diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols new file mode 100644 index 0000000000..b196d73335 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols @@ -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 diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.types b/tests/baselines/reference/asiPreventsParsingAsNamespace01.types new file mode 100644 index 0000000000..417a96dbed --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.types @@ -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 diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.js b/tests/baselines/reference/asiPreventsParsingAsNamespace02.js new file mode 100644 index 0000000000..514a026dc7 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.js @@ -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 diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols new file mode 100644 index 0000000000..a3bb37c73b --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols @@ -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 diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.types b/tests/baselines/reference/asiPreventsParsingAsNamespace02.types new file mode 100644 index 0000000000..e9e1433be7 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.types @@ -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 diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.js b/tests/baselines/reference/asiPreventsParsingAsNamespace03.js new file mode 100644 index 0000000000..3c27694f5c --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.js @@ -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 = {})); diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols new file mode 100644 index 0000000000..e77d012a1b --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols @@ -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 +} diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.types b/tests/baselines/reference/asiPreventsParsingAsNamespace03.types new file mode 100644 index 0000000000..f119a789e1 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.types @@ -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 +} diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace04.js b/tests/baselines/reference/asiPreventsParsingAsNamespace04.js new file mode 100644 index 0000000000..704c8893e7 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace04.js @@ -0,0 +1,8 @@ +//// [asiPreventsParsingAsNamespace04.ts] + +let module = 10; +module in {} + +//// [asiPreventsParsingAsNamespace04.js] +var module = 10; +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 new file mode 100644 index 0000000000..35f557328c --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.js @@ -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; +{ +} diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols new file mode 100644 index 0000000000..47f05862b0 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols @@ -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)) +{ +} diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.types b/tests/baselines/reference/asiPreventsParsingAsNamespace05.types new file mode 100644 index 0000000000..515147c109 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.types @@ -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 +{ +} diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js new file mode 100644 index 0000000000..b05988290c --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js @@ -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; diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols new file mode 100644 index 0000000000..fa82d53ac7 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols @@ -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)) + diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types new file mode 100644 index 0000000000..7492a698e3 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types @@ -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 + diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js new file mode 100644 index 0000000000..eae9898c8d --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js @@ -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 = {})); diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols new file mode 100644 index 0000000000..4b83dba4c5 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols @@ -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)) +} diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types new file mode 100644 index 0000000000..1e6c7a8caf --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types @@ -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 +} 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 + 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 {}; 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; 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 + 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 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/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/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 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/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 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