Remove unnecessary state from the parser.
This commit is contained in:
parent
e4f7822774
commit
c7c1d6b03b
4 changed files with 446 additions and 192 deletions
|
@ -1784,7 +1784,7 @@ module ts {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// If there are no specified types, try to infer it from the body of the get accessor if it exists.
|
// If there are no specified types, try to infer it from the body of the get accessor if it exists.
|
||||||
if (getter) {
|
if (getter && getter.body) {
|
||||||
type = getReturnTypeFromBody(getter);
|
type = getReturnTypeFromBody(getter);
|
||||||
}
|
}
|
||||||
// Otherwise, fall back to 'any'.
|
// Otherwise, fall back to 'any'.
|
||||||
|
|
|
@ -842,10 +842,9 @@ module ts {
|
||||||
var identifierCount = 0;
|
var identifierCount = 0;
|
||||||
var nodeCount = 0;
|
var nodeCount = 0;
|
||||||
var lineStarts: number[];
|
var lineStarts: number[];
|
||||||
var isInStrictMode = false;
|
|
||||||
|
|
||||||
|
var isInStrictMode = false;
|
||||||
var lookAheadMode = LookAheadMode.NotLookingAhead;
|
var lookAheadMode = LookAheadMode.NotLookingAhead;
|
||||||
var inAmbientContext = false;
|
|
||||||
|
|
||||||
function getLineStarts(): number[] {
|
function getLineStarts(): number[] {
|
||||||
return lineStarts || (lineStarts = computeLineStarts(sourceText));
|
return lineStarts || (lineStarts = computeLineStarts(sourceText));
|
||||||
|
@ -3046,16 +3045,7 @@ module ts {
|
||||||
node.typeParameters = sig.typeParameters;
|
node.typeParameters = sig.typeParameters;
|
||||||
node.parameters = sig.parameters;
|
node.parameters = sig.parameters;
|
||||||
node.type = sig.type;
|
node.type = sig.type;
|
||||||
|
node.body = parseFunctionBlockOrSemicolon();
|
||||||
// A common error is to try to declare an accessor in an ambient class.
|
|
||||||
if (inAmbientContext && canParseSemicolon()) {
|
|
||||||
parseSemicolon();
|
|
||||||
node.body = <Block>createMissingNode();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
node.body = parseFunctionBlock(/* ignoreMissingOpenBrace */ false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return finishNode(node);
|
return finishNode(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3260,13 +3250,7 @@ module ts {
|
||||||
var node = <ModuleDeclaration>createNode(SyntaxKind.ModuleDeclaration, pos);
|
var node = <ModuleDeclaration>createNode(SyntaxKind.ModuleDeclaration, pos);
|
||||||
node.flags = flags;
|
node.flags = flags;
|
||||||
node.name = parseStringLiteral();
|
node.name = parseStringLiteral();
|
||||||
|
|
||||||
// For error recovery, just in case the user forgot the declare modifier on this ambient
|
|
||||||
// external module, treat it as ambient anyway.
|
|
||||||
var saveInAmbientContext = inAmbientContext;
|
|
||||||
inAmbientContext = true;
|
|
||||||
node.body = parseModuleBody();
|
node.body = parseModuleBody();
|
||||||
inAmbientContext = saveInAmbientContext;
|
|
||||||
return finishNode(node);
|
return finishNode(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3345,10 +3329,6 @@ module ts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var saveInAmbientContext = inAmbientContext;
|
|
||||||
if (modifiers && modifiers.flags & NodeFlags.Ambient) {
|
|
||||||
inAmbientContext = true;
|
|
||||||
}
|
|
||||||
var flags = modifiers ? modifiers.flags : 0;
|
var flags = modifiers ? modifiers.flags : 0;
|
||||||
var result: Declaration;
|
var result: Declaration;
|
||||||
switch (token) {
|
switch (token) {
|
||||||
|
@ -3394,7 +3374,6 @@ module ts {
|
||||||
result.modifiers = modifiers;
|
result.modifiers = modifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
inAmbientContext = saveInAmbientContext;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3494,7 +3473,6 @@ module ts {
|
||||||
var rootNodeFlags: NodeFlags = 0;
|
var rootNodeFlags: NodeFlags = 0;
|
||||||
if (fileExtensionIs(filename, ".d.ts")) {
|
if (fileExtensionIs(filename, ".d.ts")) {
|
||||||
rootNodeFlags = NodeFlags.DeclarationFile;
|
rootNodeFlags = NodeFlags.DeclarationFile;
|
||||||
inAmbientContext = true;
|
|
||||||
}
|
}
|
||||||
file = <SourceFileInternal>createRootNode(SyntaxKind.SourceFile, 0, sourceText.length, rootNodeFlags);
|
file = <SourceFileInternal>createRootNode(SyntaxKind.SourceFile, 0, sourceText.length, rootNodeFlags);
|
||||||
file.filename = normalizePath(filename);
|
file.filename = normalizePath(filename);
|
||||||
|
@ -4493,6 +4471,9 @@ module ts {
|
||||||
else if (inAmbientContext) {
|
else if (inAmbientContext) {
|
||||||
return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context);
|
return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context);
|
||||||
}
|
}
|
||||||
|
else if (accessor.body === undefined) {
|
||||||
|
return grammarErrorAtPos(accessor.end - 1, ";".length, Diagnostics._0_expected, "{");
|
||||||
|
}
|
||||||
else if (accessor.typeParameters) {
|
else if (accessor.typeParameters) {
|
||||||
return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_have_type_parameters);
|
return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_have_type_parameters);
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -11,13 +11,12 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr
|
||||||
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(16,6): error TS1005: ':' expected.
|
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(16,6): error TS1005: ':' expected.
|
||||||
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(17,6): error TS1005: ':' expected.
|
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(17,6): error TS1005: ':' expected.
|
||||||
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(20,17): error TS1005: ':' expected.
|
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(20,17): error TS1005: ':' expected.
|
||||||
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
|
|
||||||
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(15,5): error TS2300: Duplicate identifier 'a'.
|
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(15,5): error TS2300: Duplicate identifier 'a'.
|
||||||
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(16,5): error TS2300: Duplicate identifier 'a'.
|
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(16,5): error TS2300: Duplicate identifier 'a'.
|
||||||
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(17,5): error TS2300: Duplicate identifier 'a'.
|
tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(17,5): error TS2300: Duplicate identifier 'a'.
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts (17 errors) ====
|
==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts (16 errors) ====
|
||||||
// errors
|
// errors
|
||||||
var y = {
|
var y = {
|
||||||
"stringLiteral",
|
"stringLiteral",
|
||||||
|
@ -29,8 +28,6 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr
|
||||||
get e,
|
get e,
|
||||||
~
|
~
|
||||||
!!! error TS1005: '(' expected.
|
!!! error TS1005: '(' expected.
|
||||||
~
|
|
||||||
!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
|
|
||||||
set f,
|
set f,
|
||||||
~
|
~
|
||||||
!!! error TS1005: '(' expected.
|
!!! error TS1005: '(' expected.
|
||||||
|
|
Loading…
Reference in a new issue