Simplify module name parsing.
Conflicts: src/services/syntax/SyntaxGenerator.js.map
This commit is contained in:
parent
fc25dfbf1a
commit
535dc0dc46
10 changed files with 41 additions and 47 deletions
|
@ -999,7 +999,6 @@ var definitions = [
|
|||
{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
|
||||
{ name: 'moduleKeyword', isToken: true, excludeFromAST: true },
|
||||
{ name: 'name', type: 'INameSyntax', isOptional: true },
|
||||
{ name: 'stringLiteral', isToken: true, isOptional: true, tokenKinds: ['StringLiteral'] },
|
||||
{ name: 'openBraceToken', isToken: true, excludeFromAST: true },
|
||||
{ name: 'moduleElements', isList: true, elementType: 'IModuleElementSyntax' },
|
||||
{ name: 'closeBraceToken', isToken: true, excludeFromAST: true }
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1240,23 +1240,18 @@ module TypeScript.Parser {
|
|||
return new FunctionDeclarationSyntax(parseNodeData, modifiers, functionKeyword, identifier, callSignature, block, semicolonToken);
|
||||
}
|
||||
|
||||
function parseModuleName(): INameSyntax {
|
||||
return currentToken().kind === SyntaxKind.StringLiteral
|
||||
? eatToken(SyntaxKind.StringLiteral)
|
||||
: parseName(/*allowIdentifierNames*/ false);
|
||||
}
|
||||
|
||||
function parseModuleDeclaration(): ModuleDeclarationSyntax {
|
||||
var modifiers = parseModifiers();
|
||||
var moduleKeyword = eatToken(SyntaxKind.ModuleKeyword);
|
||||
|
||||
var moduleName: INameSyntax = undefined;
|
||||
var stringLiteral: ISyntaxToken = undefined;
|
||||
|
||||
if (currentToken().kind === SyntaxKind.StringLiteral) {
|
||||
stringLiteral = eatToken(SyntaxKind.StringLiteral);
|
||||
}
|
||||
else {
|
||||
moduleName = parseName(/*allowIdentifierNames*/ false);
|
||||
}
|
||||
|
||||
var openBraceToken: ISyntaxToken;
|
||||
return new ModuleDeclarationSyntax(parseNodeData,
|
||||
modifiers, moduleKeyword, moduleName, stringLiteral,
|
||||
parseModifiers(),
|
||||
eatToken(SyntaxKind.ModuleKeyword),
|
||||
parseModuleName(),
|
||||
openBraceToken = eatToken(SyntaxKind.OpenBraceToken),
|
||||
openBraceToken.fullWidth() > 0 ? parseSyntaxList<IModuleElementSyntax>(ListParsingState.ModuleDeclaration_ModuleElements) : [],
|
||||
eatToken(SyntaxKind.CloseBraceToken));
|
||||
|
@ -3595,17 +3590,18 @@ module TypeScript.Parser {
|
|||
}
|
||||
|
||||
function parseFunctionType(): FunctionTypeSyntax {
|
||||
var typeParameterList = tryParseTypeParameterList(/*requireCompleteTypeParameterList:*/ false);
|
||||
var parameterList = parseParameterList();
|
||||
|
||||
return new FunctionTypeSyntax(parseNodeData,
|
||||
typeParameterList, parameterList, eatToken(SyntaxKind.EqualsGreaterThanToken), parseType());
|
||||
tryParseTypeParameterList(/*requireCompleteTypeParameterList:*/ false),
|
||||
parseParameterList(),
|
||||
eatToken(SyntaxKind.EqualsGreaterThanToken), parseType());
|
||||
}
|
||||
|
||||
function parseConstructorType(): ConstructorTypeSyntax {
|
||||
return new ConstructorTypeSyntax(parseNodeData,
|
||||
eatToken(SyntaxKind.NewKeyword), tryParseTypeParameterList(/*requireCompleteTypeParameterList:*/ false),
|
||||
parseParameterList(), eatToken(SyntaxKind.EqualsGreaterThanToken), parseType());
|
||||
eatToken(SyntaxKind.NewKeyword),
|
||||
tryParseTypeParameterList(/*requireCompleteTypeParameterList:*/ false),
|
||||
parseParameterList(),
|
||||
eatToken(SyntaxKind.EqualsGreaterThanToken), parseType());
|
||||
}
|
||||
|
||||
function isParameter(): boolean {
|
||||
|
|
|
@ -305,9 +305,6 @@ module TypeScript.PrettyPrinter {
|
|||
this.ensureSpace();
|
||||
this.appendElement(node.name);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.stringLiteral);
|
||||
this.ensureSpace();
|
||||
|
||||
this.appendToken(node.openBraceToken);
|
||||
this.ensureNewLine();
|
||||
|
||||
|
|
|
@ -145,7 +145,6 @@ var definitions:ITypeDefinition[] = [
|
|||
<any>{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
|
||||
<any>{ name: 'moduleKeyword', isToken: true, excludeFromAST: true },
|
||||
<any>{ name: 'name', type: 'INameSyntax', isOptional: true },
|
||||
<any>{ name: 'stringLiteral', isToken: true, isOptional: true, tokenKinds: ['StringLiteral'] },
|
||||
<any>{ name: 'openBraceToken', isToken: true, excludeFromAST: true },
|
||||
<any>{ name: 'moduleElements', isList: true, elementType: 'IModuleElementSyntax' },
|
||||
<any>{ name: 'closeBraceToken', isToken: true, excludeFromAST: true }
|
||||
|
|
|
@ -103,12 +103,11 @@ module TypeScript {
|
|||
modifiers: ISyntaxToken[];
|
||||
moduleKeyword: ISyntaxToken;
|
||||
name: INameSyntax;
|
||||
stringLiteral: ISyntaxToken;
|
||||
openBraceToken: ISyntaxToken;
|
||||
moduleElements: IModuleElementSyntax[];
|
||||
closeBraceToken: ISyntaxToken;
|
||||
}
|
||||
export interface ModuleDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], moduleKeyword: ISyntaxToken, name: INameSyntax, stringLiteral: ISyntaxToken, openBraceToken: ISyntaxToken, moduleElements: IModuleElementSyntax[], closeBraceToken: ISyntaxToken): ModuleDeclarationSyntax }
|
||||
export interface ModuleDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], moduleKeyword: ISyntaxToken, name: INameSyntax, openBraceToken: ISyntaxToken, moduleElements: IModuleElementSyntax[], closeBraceToken: ISyntaxToken): ModuleDeclarationSyntax }
|
||||
|
||||
export interface ClassDeclarationSyntax extends ISyntaxNode, IModuleElementSyntax {
|
||||
modifiers: ISyntaxToken[];
|
||||
|
|
|
@ -19,11 +19,11 @@ module TypeScript {
|
|||
|
||||
module TypeScript {
|
||||
export function separatorCount(list: ISeparatedSyntaxList<ISyntaxNodeOrToken>) {
|
||||
return list.length >> 1;
|
||||
return list === undefined ? 0 : list.length >> 1;
|
||||
}
|
||||
|
||||
export function nonSeparatorCount(list: ISeparatedSyntaxList<ISyntaxNodeOrToken>) {
|
||||
return (list.length + 1) >> 1;
|
||||
return list === undefined ? 0 : (list.length + 1) >> 1;
|
||||
}
|
||||
|
||||
export function separatorAt(list: ISeparatedSyntaxList<ISyntaxNodeOrToken>, index: number): ISyntaxToken {
|
||||
|
@ -48,16 +48,20 @@ module TypeScript.Syntax {
|
|||
addArrayPrototypeValue("kind", SyntaxKind.List);
|
||||
|
||||
export function list<T extends ISyntaxNodeOrToken>(nodes: T[]): T[] {
|
||||
for (var i = 0, n = nodes.length; i < n; i++) {
|
||||
nodes[i].parent = nodes;
|
||||
if (nodes !== undefined) {
|
||||
for (var i = 0, n = nodes.length; i < n; i++) {
|
||||
nodes[i].parent = nodes;
|
||||
}
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
export function separatedList<T extends ISyntaxNodeOrToken>(nodesAndTokens: ISyntaxNodeOrToken[]): ISeparatedSyntaxList<T> {
|
||||
for (var i = 0, n = nodesAndTokens.length; i < n; i++) {
|
||||
nodesAndTokens[i].parent = nodesAndTokens;
|
||||
if (nodesAndTokens !== undefined) {
|
||||
for (var i = 0, n = nodesAndTokens.length; i < n; i++) {
|
||||
nodesAndTokens[i].parent = nodesAndTokens;
|
||||
}
|
||||
}
|
||||
|
||||
return <ISeparatedSyntaxList<T>>nodesAndTokens;
|
||||
|
|
|
@ -266,34 +266,31 @@ module TypeScript {
|
|||
}
|
||||
}
|
||||
|
||||
export var ModuleDeclarationSyntax: ModuleDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], moduleKeyword: ISyntaxToken, name: INameSyntax, stringLiteral: ISyntaxToken, openBraceToken: ISyntaxToken, moduleElements: IModuleElementSyntax[], closeBraceToken: ISyntaxToken) {
|
||||
export var ModuleDeclarationSyntax: ModuleDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], moduleKeyword: ISyntaxToken, name: INameSyntax, openBraceToken: ISyntaxToken, moduleElements: IModuleElementSyntax[], closeBraceToken: ISyntaxToken) {
|
||||
if (data) { this.__data = data; }
|
||||
this.modifiers = modifiers,
|
||||
this.moduleKeyword = moduleKeyword,
|
||||
this.name = name,
|
||||
this.stringLiteral = stringLiteral,
|
||||
this.openBraceToken = openBraceToken,
|
||||
this.moduleElements = moduleElements,
|
||||
this.closeBraceToken = closeBraceToken,
|
||||
modifiers.parent = this,
|
||||
moduleKeyword.parent = this,
|
||||
name && (name.parent = this),
|
||||
stringLiteral && (stringLiteral.parent = this),
|
||||
openBraceToken.parent = this,
|
||||
moduleElements.parent = this,
|
||||
closeBraceToken.parent = this;
|
||||
};
|
||||
ModuleDeclarationSyntax.prototype.kind = SyntaxKind.ModuleDeclaration;
|
||||
ModuleDeclarationSyntax.prototype.childCount = 7;
|
||||
ModuleDeclarationSyntax.prototype.childCount = 6;
|
||||
ModuleDeclarationSyntax.prototype.childAt = function(index: number): ISyntaxElement {
|
||||
switch (index) {
|
||||
case 0: return this.modifiers;
|
||||
case 1: return this.moduleKeyword;
|
||||
case 2: return this.name;
|
||||
case 3: return this.stringLiteral;
|
||||
case 4: return this.openBraceToken;
|
||||
case 5: return this.moduleElements;
|
||||
case 6: return this.closeBraceToken;
|
||||
case 3: return this.openBraceToken;
|
||||
case 4: return this.moduleElements;
|
||||
case 5: return this.closeBraceToken;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -814,7 +814,7 @@ module TypeScript {
|
|||
}
|
||||
|
||||
private checkForDisallowedImportDeclaration(node: ModuleDeclarationSyntax): boolean {
|
||||
if (!node.stringLiteral) {
|
||||
if (node.name.kind !== SyntaxKind.StringLiteral) {
|
||||
for (var i = 0, n = node.moduleElements.length; i < n; i++) {
|
||||
var child = node.moduleElements[i];
|
||||
if (child.kind === SyntaxKind.ImportDeclaration) {
|
||||
|
@ -849,21 +849,21 @@ module TypeScript {
|
|||
|
||||
public visitModuleDeclaration(node: ModuleDeclarationSyntax): void {
|
||||
if (this.checkForDisallowedDeclareModifier(node.modifiers) ||
|
||||
this.checkForRequiredDeclareModifier(node, node.stringLiteral ? node.stringLiteral : firstToken(node.name), node.modifiers) ||
|
||||
this.checkForRequiredDeclareModifier(node, firstToken(node.name), node.modifiers) ||
|
||||
this.checkModuleElementModifiers(node.modifiers) ||
|
||||
this.checkForDisallowedImportDeclaration(node)) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.stringLiteral) {
|
||||
if (node.name.kind === SyntaxKind.StringLiteral) {
|
||||
if (!this.inAmbientDeclaration && !SyntaxUtilities.containsToken(node.modifiers, SyntaxKind.DeclareKeyword)) {
|
||||
this.pushDiagnostic(node.stringLiteral, DiagnosticCode.Only_ambient_modules_can_use_quoted_names);
|
||||
this.pushDiagnostic(node.name, DiagnosticCode.Only_ambient_modules_can_use_quoted_names);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!node.stringLiteral && this.checkForDisallowedExportAssignment(node)) {
|
||||
if (node.name.kind !== SyntaxKind.StringLiteral && this.checkForDisallowedExportAssignment(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,6 @@ module TypeScript {
|
|||
this.visitList(node.modifiers);
|
||||
this.visitToken(node.moduleKeyword);
|
||||
visitNodeOrToken(this, node.name);
|
||||
this.visitOptionalToken(node.stringLiteral);
|
||||
this.visitToken(node.openBraceToken);
|
||||
this.visitList(node.moduleElements);
|
||||
this.visitToken(node.closeBraceToken);
|
||||
|
|
Loading…
Reference in a new issue