Allow parsing a qualified type name containing a reserved word (#18888)

This commit is contained in:
Andy 2017-10-02 17:04:28 -07:00 committed by GitHub
parent b244cd4fb4
commit 3a2c723a69
15 changed files with 81 additions and 52 deletions

View file

@ -1217,8 +1217,8 @@ namespace ts {
return createIdentifier(isIdentifier(), diagnosticMessage);
}
function parseIdentifierName(): Identifier {
return createIdentifier(tokenIsIdentifierOrKeyword(token()));
function parseIdentifierName(diagnosticMessage?: DiagnosticMessage): Identifier {
return createIdentifier(tokenIsIdentifierOrKeyword(token()), diagnosticMessage);
}
function isLiteralPropertyName(): boolean {
@ -1956,7 +1956,7 @@ namespace ts {
}
function parseEntityName(allowReservedWords: boolean, diagnosticMessage?: DiagnosticMessage): EntityName {
let entity: EntityName = allowReservedWords ? parseIdentifierName() : parseIdentifier(diagnosticMessage);
let entity: EntityName = allowReservedWords ? parseIdentifierName(diagnosticMessage) : parseIdentifier(diagnosticMessage);
let dotPos = scanner.getStartPos();
while (parseOptional(SyntaxKind.DotToken)) {
if (token() === SyntaxKind.LessThanToken) {
@ -2096,7 +2096,7 @@ namespace ts {
function parseTypeReference(): TypeReferenceNode {
const node = <TypeReferenceNode>createNode(SyntaxKind.TypeReference);
node.typeName = parseEntityName(/*allowReservedWords*/ !!(contextFlags & NodeFlags.JSDoc), Diagnostics.Type_expected);
node.typeName = parseEntityName(/*allowReservedWords*/ true, Diagnostics.Type_expected);
if (!scanner.hasPrecedingLineBreak() && token() === SyntaxKind.LessThanToken) {
node.typeArguments = parseBracketedList(ParsingContext.TypeArguments, parseType, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken);
}

View file

@ -1,16 +1,18 @@
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(8,8): error TS1110: Type expected.
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(8,8): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(8,8): error TS2304: Cannot find name 'super'.
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(8,13): error TS1005: '=' expected.
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(8,14): error TS1109: Expression expected.
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(10,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(13,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(17,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(20,15): error TS1110: Type expected.
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(20,15): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(20,15): error TS2304: Cannot find name 'super'.
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(20,20): error TS1005: '=' expected.
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(20,21): error TS1109: Expression expected.
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(22,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(25,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(29,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts (10 errors) ====
==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts (12 errors) ====
// error to use super calls outside a constructor
class Base {
@ -20,9 +22,11 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS
class Derived extends Base {
a: super();
~~~~~
!!! error TS1110: Type expected.
~~~~~
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
!!! error TS2304: Cannot find name 'super'.
~
!!! error TS1005: '=' expected.
~
!!! error TS1109: Expression expected.
b() {
super();
~~~~~
@ -42,9 +46,11 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS
static a: super();
~~~~~
!!! error TS1110: Type expected.
~~~~~
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
!!! error TS2304: Cannot find name 'super'.
~
!!! error TS1005: '=' expected.
~
!!! error TS1109: Expression expected.
static b() {
super();
~~~~~

View file

@ -52,7 +52,7 @@ var Derived = /** @class */ (function (_super) {
__extends(Derived, _super);
function Derived() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.a = _this = _super.call(this) || this;
_this.a = ();
return _this;
}
Derived.prototype.b = function () {
@ -83,6 +83,6 @@ var Derived = /** @class */ (function (_super) {
enumerable: true,
configurable: true
});
Derived.a = _this = _super.call(this) || this;
Derived.a = ();
return Derived;
}(Base));

View file

@ -14,9 +14,9 @@ class Derived extends Base {
a: super();
>a : any
> : No type information available!
>super() : void
>super : any
>super : No type information available!
>() : any
> : any
b() {
>b : () => void
@ -46,9 +46,9 @@ class Derived extends Base {
static a: super();
>a : any
> : No type information available!
>super() : void
>super : any
>super : No type information available!
>() : any
> : any
static b() {
>b : () => void

View file

@ -1,4 +1,4 @@
tests/cases/compiler/example.js(3,20): error TS1003: Identifier expected.
tests/cases/compiler/example.js(3,20): error TS1110: Type expected.
==== tests/cases/compiler/example.js (1 errors) ====
@ -6,6 +6,6 @@ tests/cases/compiler/example.js(3,20): error TS1003: Identifier expected.
/**
* @type {function(@foo)}
~
!!! error TS1003: Identifier expected.
!!! error TS1110: Type expected.
*/
let x;

View file

@ -0,0 +1,11 @@
//// [parseEntityNameWithReservedWord.ts]
enum Bool { false }
const x: Bool.false = Bool.false;
//// [parseEntityNameWithReservedWord.js]
var Bool;
(function (Bool) {
Bool[Bool["false"] = 0] = "false";
})(Bool || (Bool = {}));
var x = Bool["false"];

View file

@ -0,0 +1,13 @@
=== tests/cases/compiler/parseEntityNameWithReservedWord.ts ===
enum Bool { false }
>Bool : Symbol(Bool, Decl(parseEntityNameWithReservedWord.ts, 0, 0))
>false : Symbol(Bool.false, Decl(parseEntityNameWithReservedWord.ts, 0, 11))
const x: Bool.false = Bool.false;
>x : Symbol(x, Decl(parseEntityNameWithReservedWord.ts, 1, 5))
>Bool : Symbol(Bool, Decl(parseEntityNameWithReservedWord.ts, 0, 0))
>false : Symbol(Bool.false, Decl(parseEntityNameWithReservedWord.ts, 0, 11))
>Bool.false : Symbol(Bool.false, Decl(parseEntityNameWithReservedWord.ts, 0, 11))
>Bool : Symbol(Bool, Decl(parseEntityNameWithReservedWord.ts, 0, 0))
>false : Symbol(Bool.false, Decl(parseEntityNameWithReservedWord.ts, 0, 11))

View file

@ -0,0 +1,13 @@
=== tests/cases/compiler/parseEntityNameWithReservedWord.ts ===
enum Bool { false }
>Bool : Bool
>false : Bool
const x: Bool.false = Bool.false;
>x : Bool
>Bool : any
>false : Bool
>Bool.false : Bool
>Bool : typeof Bool
>false : Bool

View file

@ -1,15 +1,9 @@
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList6.ts(2,23): error TS1110: Type expected.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList6.ts(2,28): error TS1003: Identifier expected.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList6.ts(3,1): error TS1128: Declaration or statement expected.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList6.ts(2,23): error TS2304: Cannot find name 'break'.
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList6.ts (3 errors) ====
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList6.ts (1 errors) ====
class Foo {
public banana (x: break) { }
~~~~~
!!! error TS1110: Type expected.
~
!!! error TS1003: Identifier expected.
}
~
!!! error TS1128: Declaration or statement expected.
!!! error TS2304: Cannot find name 'break'.
}

View file

@ -7,7 +7,6 @@ class Foo {
var Foo = /** @class */ (function () {
function Foo() {
}
Foo.prototype.banana = function (x) { };
return Foo;
}());
break ;
{ }

View file

@ -3,8 +3,7 @@ class Foo {
>Foo : Foo
public banana (x: break) { }
>banana : (x: any) => any
>banana : (x: any) => void
>x : any
> : No type information available!
> : any
>break : No type information available!
}

View file

@ -1,13 +1,7 @@
tests/cases/conformance/parser/ecmascript5/parservoidInQualifiedName2.ts(1,9): error TS2503: Cannot find namespace 'x'.
tests/cases/conformance/parser/ecmascript5/parservoidInQualifiedName2.ts(1,11): error TS1003: Identifier expected.
tests/cases/conformance/parser/ecmascript5/parservoidInQualifiedName2.ts(1,15): error TS1109: Expression expected.
==== tests/cases/conformance/parser/ecmascript5/parservoidInQualifiedName2.ts (3 errors) ====
==== tests/cases/conformance/parser/ecmascript5/parservoidInQualifiedName2.ts (1 errors) ====
var v : x.void;
~
!!! error TS2503: Cannot find namespace 'x'.
~~~~
!!! error TS1003: Identifier expected.
~
!!! error TS1109: Expression expected.
!!! error TS2503: Cannot find namespace 'x'.

View file

@ -2,4 +2,4 @@
var v : x.void;
//// [parservoidInQualifiedName2.js]
var v = void ;
var v;

View file

@ -2,7 +2,5 @@
var v : x.void;
>v : any
>x : any
> : No type information available!
>void : undefined
> : any
>void : No type information available!

View file

@ -0,0 +1,2 @@
enum Bool { false }
const x: Bool.false = Bool.false;