mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 02:15:12 -06:00
Merge pull request #11342 from Microsoft/syntaxKindLiterals
Added literal kind properties for each node.
This commit is contained in:
commit
4a5f56fc78
@ -18,8 +18,13 @@ class TypeOperatorSpacingWalker extends Lint.RuleWalker {
|
||||
for (let i = 1; i < types.length; i++) {
|
||||
const currentType = types[i];
|
||||
if (expectedStart !== currentType.pos || currentType.getLeadingTriviaWidth() !== 1) {
|
||||
const failure = this.createFailure(currentType.pos, currentType.getWidth(), Rule.FAILURE_STRING);
|
||||
this.addFailure(failure);
|
||||
const sourceFile = currentType.getSourceFile();
|
||||
const previousTypeEndPos = sourceFile.getLineAndCharacterOfPosition(types[i - 1].end);
|
||||
const currentTypeStartPos = sourceFile.getLineAndCharacterOfPosition(currentType.pos);
|
||||
if (previousTypeEndPos.line === currentTypeStartPos.line) {
|
||||
const failure = this.createFailure(currentType.pos, currentType.getWidth(), Rule.FAILURE_STRING);
|
||||
this.addFailure(failure);
|
||||
}
|
||||
}
|
||||
expectedStart = currentType.end + 2;
|
||||
}
|
||||
|
||||
@ -1111,7 +1111,7 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
forEachChild(node, bind);
|
||||
if (node.operator === SyntaxKind.PlusEqualsToken || node.operator === SyntaxKind.MinusMinusToken) {
|
||||
if (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) {
|
||||
bindAssignmentTargetFlow(node.operand);
|
||||
}
|
||||
}
|
||||
@ -1360,7 +1360,7 @@ namespace ts {
|
||||
function hasExportDeclarations(node: ModuleDeclaration | SourceFile): boolean {
|
||||
const body = node.kind === SyntaxKind.SourceFile ? node : (<ModuleDeclaration>node).body;
|
||||
if (body && (body.kind === SyntaxKind.SourceFile || body.kind === SyntaxKind.ModuleBlock)) {
|
||||
for (const stat of (<Block>body).statements) {
|
||||
for (const stat of (<BlockLike>body).statements) {
|
||||
if (stat.kind === SyntaxKind.ExportDeclaration || stat.kind === SyntaxKind.ExportAssignment) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -3892,7 +3892,7 @@ namespace ts {
|
||||
if (!links.declaredType) {
|
||||
const enumType = <EnumType>getDeclaredTypeOfEnum(getParentOfSymbol(symbol));
|
||||
links.declaredType = enumType.flags & TypeFlags.Union ?
|
||||
enumType.memberTypes[getEnumMemberValue(<EnumDeclaration>symbol.valueDeclaration)] :
|
||||
enumType.memberTypes[getEnumMemberValue(<EnumMember>symbol.valueDeclaration)] :
|
||||
enumType;
|
||||
}
|
||||
return links.declaredType;
|
||||
@ -6075,7 +6075,7 @@ namespace ts {
|
||||
return !node.typeParameters && areAllParametersUntyped && !isNullaryArrow;
|
||||
}
|
||||
|
||||
function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | MethodDeclaration {
|
||||
function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | ArrowFunction | MethodDeclaration {
|
||||
return (isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) && isContextSensitiveFunctionLikeDeclaration(func);
|
||||
}
|
||||
|
||||
@ -9271,7 +9271,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function findFirstSuperCall(n: Node): Node {
|
||||
if (isSuperCallExpression(n)) {
|
||||
if (isSuperCall(n)) {
|
||||
return n;
|
||||
}
|
||||
else if (isFunctionLike(n)) {
|
||||
@ -9780,7 +9780,7 @@ namespace ts {
|
||||
// corresponding set accessor has a type annotation, return statements in the function are contextually typed
|
||||
if (functionDecl.type ||
|
||||
functionDecl.kind === SyntaxKind.Constructor ||
|
||||
functionDecl.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(<AccessorDeclaration>getDeclarationOfKind(functionDecl.symbol, SyntaxKind.SetAccessor))) {
|
||||
functionDecl.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(<SetAccessorDeclaration>getDeclarationOfKind(functionDecl.symbol, SyntaxKind.SetAccessor))) {
|
||||
return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl));
|
||||
}
|
||||
|
||||
@ -10049,7 +10049,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isFunctionExpressionOrArrowFunction(node: Node): node is FunctionExpression {
|
||||
function isFunctionExpressionOrArrowFunction(node: Node): node is FunctionExpression | ArrowFunction {
|
||||
return node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.ArrowFunction;
|
||||
}
|
||||
|
||||
@ -10060,7 +10060,7 @@ namespace ts {
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function getContextualTypeForFunctionLikeDeclaration(node: FunctionExpression | MethodDeclaration) {
|
||||
function getContextualTypeForFunctionLikeDeclaration(node: FunctionExpression | ArrowFunction | MethodDeclaration) {
|
||||
return isObjectLiteralMethod(node) ?
|
||||
getContextualTypeForObjectLiteralMethod(node) :
|
||||
getApparentTypeOfContextualType(node);
|
||||
@ -10071,7 +10071,7 @@ namespace ts {
|
||||
// If the contextual type is a union type, get the signature from each type possible and if they are
|
||||
// all identical ignoring their return type, the result is same signature but with return type as
|
||||
// union type of return types from these signatures
|
||||
function getContextualSignature(node: FunctionExpression | MethodDeclaration): Signature {
|
||||
function getContextualSignature(node: FunctionExpression | ArrowFunction | MethodDeclaration): Signature {
|
||||
Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node));
|
||||
const type = getContextualTypeForFunctionLikeDeclaration(node);
|
||||
if (!type) {
|
||||
@ -11423,7 +11423,7 @@ namespace ts {
|
||||
argCount = getEffectiveArgumentCount(node, /*args*/ undefined, signature);
|
||||
}
|
||||
else {
|
||||
const callExpression = <CallExpression>node;
|
||||
const callExpression = <CallExpression | NewExpression>node;
|
||||
if (!callExpression.arguments) {
|
||||
// This only happens when we have something of the form: 'new C'
|
||||
Debug.assert(callExpression.kind === SyntaxKind.NewExpression);
|
||||
@ -11434,7 +11434,7 @@ namespace ts {
|
||||
argCount = signatureHelpTrailingComma ? args.length + 1 : args.length;
|
||||
|
||||
// If we are missing the close paren, the call is incomplete.
|
||||
callIsIncomplete = (<CallExpression>callExpression).arguments.end === callExpression.end;
|
||||
callIsIncomplete = callExpression.arguments.end === callExpression.end;
|
||||
|
||||
typeArguments = callExpression.typeArguments;
|
||||
spreadArgIndex = getSpreadArgumentIndex(args);
|
||||
@ -12521,7 +12521,7 @@ namespace ts {
|
||||
* @param node The call/new expression to be checked.
|
||||
* @returns On success, the expression's signature's return type. On failure, anyType.
|
||||
*/
|
||||
function checkCallExpression(node: CallExpression): Type {
|
||||
function checkCallExpression(node: CallExpression | NewExpression): Type {
|
||||
// Grammar checking; stop grammar-checking if checkGrammarTypeArguments return true
|
||||
checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments);
|
||||
|
||||
@ -12979,7 +12979,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
if (produceDiagnostics && node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) {
|
||||
if (produceDiagnostics && node.kind !== SyntaxKind.MethodDeclaration) {
|
||||
checkCollisionWithCapturedSuperVariable(node, (<FunctionExpression>node).name);
|
||||
checkCollisionWithCapturedThisVariable(node, (<FunctionExpression>node).name);
|
||||
}
|
||||
@ -14441,7 +14441,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function containsSuperCall(n: Node): boolean {
|
||||
if (isSuperCallExpression(n)) {
|
||||
if (isSuperCall(n)) {
|
||||
return true;
|
||||
}
|
||||
else if (isFunctionLike(n)) {
|
||||
@ -14497,7 +14497,7 @@ namespace ts {
|
||||
let superCallStatement: ExpressionStatement;
|
||||
|
||||
for (const statement of statements) {
|
||||
if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((<ExpressionStatement>statement).expression)) {
|
||||
if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCall((<ExpressionStatement>statement).expression)) {
|
||||
superCallStatement = <ExpressionStatement>statement;
|
||||
break;
|
||||
}
|
||||
@ -16457,7 +16457,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function isGetAccessorWithAnnotatedSetAccessor(node: FunctionLikeDeclaration) {
|
||||
return !!(node.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(<AccessorDeclaration>getDeclarationOfKind(node.symbol, SyntaxKind.SetAccessor)));
|
||||
return !!(node.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(<SetAccessorDeclaration>getDeclarationOfKind(node.symbol, SyntaxKind.SetAccessor)));
|
||||
}
|
||||
|
||||
function isUnwrappedReturnTypeVoidOrAny(func: FunctionLikeDeclaration, returnType: Type): boolean {
|
||||
@ -17449,9 +17449,12 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
checkCollisionWithCapturedThisVariable(node, node.name);
|
||||
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
|
||||
checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name);
|
||||
if (isIdentifier(node.name)) {
|
||||
checkCollisionWithCapturedThisVariable(node, node.name);
|
||||
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
|
||||
checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name);
|
||||
}
|
||||
|
||||
checkExportsOnMergedDeclarations(node);
|
||||
const symbol = getSymbolOfNode(node);
|
||||
|
||||
@ -19073,7 +19076,7 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function isLiteralConstDeclaration(node: VariableDeclaration): boolean {
|
||||
function isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean {
|
||||
if (isConst(node)) {
|
||||
const type = getTypeOfSymbol(getSymbolOfNode(node));
|
||||
return !!(type.flags & TypeFlags.StringOrNumberLiteral && type.flags & TypeFlags.FreshLiteral);
|
||||
@ -19081,7 +19084,7 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function writeLiteralConstValue(node: VariableDeclaration, writer: SymbolWriter) {
|
||||
function writeLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, writer: SymbolWriter) {
|
||||
const type = getTypeOfSymbol(getSymbolOfNode(node));
|
||||
writer.writeStringLiteral(literalTypeToString(<LiteralType>type));
|
||||
}
|
||||
@ -19818,7 +19821,7 @@ namespace ts {
|
||||
checkGrammarForAtLeastOneTypeArgument(node, typeArguments);
|
||||
}
|
||||
|
||||
function checkGrammarForOmittedArgument(node: CallExpression, args: NodeArray<Expression>): boolean {
|
||||
function checkGrammarForOmittedArgument(node: CallExpression | NewExpression, args: NodeArray<Expression>): boolean {
|
||||
if (args) {
|
||||
const sourceFile = getSourceFileOfNode(node);
|
||||
for (const arg of args) {
|
||||
@ -19829,7 +19832,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkGrammarArguments(node: CallExpression, args: NodeArray<Expression>): boolean {
|
||||
function checkGrammarArguments(node: CallExpression | NewExpression, args: NodeArray<Expression>): boolean {
|
||||
return checkGrammarForOmittedArgument(node, args);
|
||||
}
|
||||
|
||||
@ -19951,8 +19954,7 @@ namespace ts {
|
||||
|
||||
for (const prop of node.properties) {
|
||||
const name = prop.name;
|
||||
if (prop.kind === SyntaxKind.OmittedExpression ||
|
||||
name.kind === SyntaxKind.ComputedPropertyName) {
|
||||
if (name.kind === SyntaxKind.ComputedPropertyName) {
|
||||
// If the name is not a ComputedPropertyName, the grammar checking will skip it
|
||||
checkGrammarComputedPropertyName(<ComputedPropertyName>name);
|
||||
}
|
||||
@ -19999,7 +20001,7 @@ namespace ts {
|
||||
currentKind = SetAccessor;
|
||||
}
|
||||
else {
|
||||
Debug.fail("Unexpected syntax kind:" + prop.kind);
|
||||
Debug.fail("Unexpected syntax kind:" + (<Node>prop).kind);
|
||||
}
|
||||
|
||||
const effectiveName = getPropertyNameForPropertyNameNode(name);
|
||||
|
||||
@ -1813,9 +1813,9 @@ namespace ts {
|
||||
|
||||
export interface ObjectAllocator {
|
||||
getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node;
|
||||
getTokenConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Token;
|
||||
getIdentifierConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Token;
|
||||
getSourceFileConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => SourceFile;
|
||||
getTokenConstructor(): new <TKind extends SyntaxKind>(kind: TKind, pos?: number, end?: number) => Token<TKind>;
|
||||
getIdentifierConstructor(): new (kind: SyntaxKind.Identifier, pos?: number, end?: number) => Identifier;
|
||||
getSourceFileConstructor(): new (kind: SyntaxKind.SourceFile, pos?: number, end?: number) => SourceFile;
|
||||
getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol;
|
||||
getTypeConstructor(): new (checker: TypeChecker, flags: TypeFlags) => Type;
|
||||
getSignatureConstructor(): new (checker: TypeChecker) => Signature;
|
||||
|
||||
@ -1121,7 +1121,7 @@ namespace ts {
|
||||
writeLine();
|
||||
}
|
||||
|
||||
function emitVariableDeclaration(node: VariableDeclaration) {
|
||||
function emitVariableDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration) {
|
||||
// If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted
|
||||
// so there is no check needed to see if declaration is visible
|
||||
if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) {
|
||||
@ -1136,7 +1136,7 @@ namespace ts {
|
||||
// If optional property emit ? but in the case of parameterProperty declaration with "?" indicating optional parameter for the constructor
|
||||
// we don't want to emit property declaration with "?"
|
||||
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature ||
|
||||
(node.kind === SyntaxKind.Parameter && !isParameterPropertyDeclaration(node))) && hasQuestionToken(node)) {
|
||||
(node.kind === SyntaxKind.Parameter && !isParameterPropertyDeclaration(<ParameterDeclaration>node))) && hasQuestionToken(node)) {
|
||||
write("?");
|
||||
}
|
||||
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) {
|
||||
@ -1626,8 +1626,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function emitBindingElement(bindingElement: BindingElement) {
|
||||
|
||||
function emitBindingElement(bindingElement: BindingElement | OmittedExpression) {
|
||||
if (bindingElement.kind === SyntaxKind.OmittedExpression) {
|
||||
// If bindingElement is an omittedExpression (i.e. containing elision),
|
||||
// we will emit blank space (although this may differ from users' original code,
|
||||
|
||||
@ -655,7 +655,7 @@ const _super = (function (geti, seti) {
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
return emitModuleDeclaration(<ModuleDeclaration>node);
|
||||
case SyntaxKind.ModuleBlock:
|
||||
return emitModuleBlock(<Block>node);
|
||||
return emitModuleBlock(<ModuleBlock>node);
|
||||
case SyntaxKind.CaseBlock:
|
||||
return emitCaseBlock(<CaseBlock>node);
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
@ -1394,7 +1394,7 @@ const _super = (function (geti, seti) {
|
||||
}
|
||||
}
|
||||
|
||||
function emitBlockStatements(node: Block) {
|
||||
function emitBlockStatements(node: BlockLike) {
|
||||
if (getEmitFlags(node) & EmitFlags.SingleLine) {
|
||||
emitList(node, node.statements, ListFormat.SingleLineBlockStatements);
|
||||
}
|
||||
@ -1795,7 +1795,7 @@ const _super = (function (geti, seti) {
|
||||
}
|
||||
|
||||
function emitModuleBlock(node: ModuleBlock) {
|
||||
if (isSingleLineEmptyBlock(node)) {
|
||||
if (isEmptyBlock(node)) {
|
||||
write("{ }");
|
||||
}
|
||||
else {
|
||||
@ -2615,7 +2615,11 @@ const _super = (function (geti, seti) {
|
||||
|
||||
function isSingleLineEmptyBlock(block: Block) {
|
||||
return !block.multiLine
|
||||
&& block.statements.length === 0
|
||||
&& isEmptyBlock(block);
|
||||
}
|
||||
|
||||
function isEmptyBlock(block: BlockLike) {
|
||||
return block.statements.length === 0
|
||||
&& rangeEndIsOnSameLineAsRangeStart(block, block, currentSourceFile);
|
||||
}
|
||||
|
||||
|
||||
@ -105,6 +105,7 @@ namespace ts {
|
||||
export function createLiteral(textSource: StringLiteral | Identifier, location?: TextRange): StringLiteral;
|
||||
export function createLiteral(value: string, location?: TextRange): StringLiteral;
|
||||
export function createLiteral(value: number, location?: TextRange): NumericLiteral;
|
||||
export function createLiteral(value: boolean, location?: TextRange): BooleanLiteral;
|
||||
export function createLiteral(value: string | number | boolean, location?: TextRange): PrimaryExpression;
|
||||
export function createLiteral(value: string | number | boolean | StringLiteral | Identifier, location?: TextRange): PrimaryExpression {
|
||||
if (typeof value === "number") {
|
||||
@ -120,7 +121,7 @@ namespace ts {
|
||||
node.text = value;
|
||||
return node;
|
||||
}
|
||||
else {
|
||||
else if (value) {
|
||||
const node = <StringLiteral>createNode(SyntaxKind.StringLiteral, location, /*flags*/ undefined);
|
||||
node.textSourceNode = value;
|
||||
node.text = value.text;
|
||||
@ -187,8 +188,8 @@ namespace ts {
|
||||
|
||||
// Punctuation
|
||||
|
||||
export function createToken(token: SyntaxKind) {
|
||||
return createNode(token);
|
||||
export function createToken<TKind extends SyntaxKind>(token: TKind) {
|
||||
return <Token<TKind>>createNode(token);
|
||||
}
|
||||
|
||||
// Reserved words
|
||||
@ -238,7 +239,7 @@ namespace ts {
|
||||
);
|
||||
}
|
||||
|
||||
export function createParameterDeclaration(decorators: Decorator[], modifiers: Modifier[], dotDotDotToken: Node, name: string | Identifier | BindingPattern, questionToken: Node, type: TypeNode, initializer: Expression, location?: TextRange, flags?: NodeFlags) {
|
||||
export function createParameterDeclaration(decorators: Decorator[], modifiers: Modifier[], dotDotDotToken: DotDotDotToken, name: string | Identifier | BindingPattern, questionToken: QuestionToken, type: TypeNode, initializer: Expression, location?: TextRange, flags?: NodeFlags) {
|
||||
const node = <ParameterDeclaration>createNode(SyntaxKind.Parameter, location, flags);
|
||||
node.decorators = decorators ? createNodeArray(decorators) : undefined;
|
||||
node.modifiers = modifiers ? createNodeArray(modifiers) : undefined;
|
||||
@ -260,7 +261,7 @@ namespace ts {
|
||||
|
||||
// Type members
|
||||
|
||||
export function createProperty(decorators: Decorator[], modifiers: Modifier[], name: string | PropertyName, questionToken: Node, type: TypeNode, initializer: Expression, location?: TextRange) {
|
||||
export function createProperty(decorators: Decorator[], modifiers: Modifier[], name: string | PropertyName, questionToken: QuestionToken, type: TypeNode, initializer: Expression, location?: TextRange) {
|
||||
const node = <PropertyDeclaration>createNode(SyntaxKind.PropertyDeclaration, location);
|
||||
node.decorators = decorators ? createNodeArray(decorators) : undefined;
|
||||
node.modifiers = modifiers ? createNodeArray(modifiers) : undefined;
|
||||
@ -278,7 +279,7 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createMethod(decorators: Decorator[], modifiers: Modifier[], asteriskToken: Node, name: string | PropertyName, typeParameters: TypeParameterDeclaration[], parameters: ParameterDeclaration[], type: TypeNode, body: Block, location?: TextRange, flags?: NodeFlags) {
|
||||
export function createMethod(decorators: Decorator[], modifiers: Modifier[], asteriskToken: AsteriskToken, name: string | PropertyName, typeParameters: TypeParameterDeclaration[], parameters: ParameterDeclaration[], type: TypeNode, body: Block, location?: TextRange, flags?: NodeFlags) {
|
||||
const node = <MethodDeclaration>createNode(SyntaxKind.MethodDeclaration, location, flags);
|
||||
node.decorators = decorators ? createNodeArray(decorators) : undefined;
|
||||
node.modifiers = modifiers ? createNodeArray(modifiers) : undefined;
|
||||
@ -381,7 +382,7 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createBindingElement(propertyName: string | PropertyName, dotDotDotToken: Node, name: string | BindingName, initializer?: Expression, location?: TextRange) {
|
||||
export function createBindingElement(propertyName: string | PropertyName, dotDotDotToken: DotDotDotToken, name: string | BindingName, initializer?: Expression, location?: TextRange) {
|
||||
const node = <BindingElement>createNode(SyntaxKind.BindingElement, location);
|
||||
node.propertyName = typeof propertyName === "string" ? createIdentifier(propertyName) : propertyName;
|
||||
node.dotDotDotToken = dotDotDotToken;
|
||||
@ -497,14 +498,14 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createTaggedTemplate(tag: Expression, template: Template, location?: TextRange) {
|
||||
export function createTaggedTemplate(tag: Expression, template: TemplateLiteral, location?: TextRange) {
|
||||
const node = <TaggedTemplateExpression>createNode(SyntaxKind.TaggedTemplateExpression, location);
|
||||
node.tag = parenthesizeForAccess(tag);
|
||||
node.template = template;
|
||||
return node;
|
||||
}
|
||||
|
||||
export function updateTaggedTemplate(node: TaggedTemplateExpression, tag: Expression, template: Template) {
|
||||
export function updateTaggedTemplate(node: TaggedTemplateExpression, tag: Expression, template: TemplateLiteral) {
|
||||
if (node.tag !== tag || node.template !== template) {
|
||||
return updateNode(createTaggedTemplate(tag, template, node), node);
|
||||
}
|
||||
@ -524,7 +525,7 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createFunctionExpression(asteriskToken: Node, name: string | Identifier, typeParameters: TypeParameterDeclaration[], parameters: ParameterDeclaration[], type: TypeNode, body: Block, location?: TextRange, flags?: NodeFlags) {
|
||||
export function createFunctionExpression(asteriskToken: AsteriskToken, name: string | Identifier, typeParameters: TypeParameterDeclaration[], parameters: ParameterDeclaration[], type: TypeNode, body: Block, location?: TextRange, flags?: NodeFlags) {
|
||||
const node = <FunctionExpression>createNode(SyntaxKind.FunctionExpression, location, flags);
|
||||
node.modifiers = undefined;
|
||||
node.asteriskToken = asteriskToken;
|
||||
@ -543,13 +544,13 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createArrowFunction(modifiers: Modifier[], typeParameters: TypeParameterDeclaration[], parameters: ParameterDeclaration[], type: TypeNode, equalsGreaterThanToken: Node, body: ConciseBody, location?: TextRange, flags?: NodeFlags) {
|
||||
export function createArrowFunction(modifiers: Modifier[], typeParameters: TypeParameterDeclaration[], parameters: ParameterDeclaration[], type: TypeNode, equalsGreaterThanToken: EqualsGreaterThanToken, body: ConciseBody, location?: TextRange, flags?: NodeFlags) {
|
||||
const node = <ArrowFunction>createNode(SyntaxKind.ArrowFunction, location, flags);
|
||||
node.modifiers = modifiers ? createNodeArray(modifiers) : undefined;
|
||||
node.typeParameters = typeParameters ? createNodeArray(typeParameters) : undefined;
|
||||
node.parameters = createNodeArray(parameters);
|
||||
node.type = type;
|
||||
node.equalsGreaterThanToken = equalsGreaterThanToken || createNode(SyntaxKind.EqualsGreaterThanToken);
|
||||
node.equalsGreaterThanToken = equalsGreaterThanToken || createToken(SyntaxKind.EqualsGreaterThanToken);
|
||||
node.body = parenthesizeConciseBody(body);
|
||||
return node;
|
||||
}
|
||||
@ -613,7 +614,7 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createPrefix(operator: SyntaxKind, operand: Expression, location?: TextRange) {
|
||||
export function createPrefix(operator: PrefixUnaryOperator, operand: Expression, location?: TextRange) {
|
||||
const node = <PrefixUnaryExpression>createNode(SyntaxKind.PrefixUnaryExpression, location);
|
||||
node.operator = operator;
|
||||
node.operand = parenthesizePrefixOperand(operand);
|
||||
@ -627,7 +628,7 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createPostfix(operand: Expression, operator: SyntaxKind, location?: TextRange) {
|
||||
export function createPostfix(operand: Expression, operator: PostfixUnaryOperator, location?: TextRange) {
|
||||
const node = <PostfixUnaryExpression>createNode(SyntaxKind.PostfixUnaryExpression, location);
|
||||
node.operand = parenthesizePostfixOperand(operand);
|
||||
node.operator = operator;
|
||||
@ -641,8 +642,8 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createBinary(left: Expression, operator: SyntaxKind | Node, right: Expression, location?: TextRange) {
|
||||
const operatorToken = typeof operator === "number" ? createSynthesizedNode(operator) : operator;
|
||||
export function createBinary(left: Expression, operator: BinaryOperator | BinaryOperatorToken, right: Expression, location?: TextRange) {
|
||||
const operatorToken = typeof operator === "number" ? createToken(operator) : operator;
|
||||
const operatorKind = operatorToken.kind;
|
||||
const node = <BinaryExpression>createNode(SyntaxKind.BinaryExpression, location);
|
||||
node.left = parenthesizeBinaryOperand(operatorKind, left, /*isLeftSideOfBinary*/ true, /*leftOperand*/ undefined);
|
||||
@ -658,7 +659,7 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createConditional(condition: Expression, questionToken: Node, whenTrue: Expression, colonToken: Node, whenFalse: Expression, location?: TextRange) {
|
||||
export function createConditional(condition: Expression, questionToken: QuestionToken, whenTrue: Expression, colonToken: ColonToken, whenFalse: Expression, location?: TextRange) {
|
||||
const node = <ConditionalExpression>createNode(SyntaxKind.ConditionalExpression, location);
|
||||
node.condition = condition;
|
||||
node.questionToken = questionToken;
|
||||
@ -675,21 +676,21 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createTemplateExpression(head: TemplateLiteralFragment, templateSpans: TemplateSpan[], location?: TextRange) {
|
||||
export function createTemplateExpression(head: TemplateHead, templateSpans: TemplateSpan[], location?: TextRange) {
|
||||
const node = <TemplateExpression>createNode(SyntaxKind.TemplateExpression, location);
|
||||
node.head = head;
|
||||
node.templateSpans = createNodeArray(templateSpans);
|
||||
return node;
|
||||
}
|
||||
|
||||
export function updateTemplateExpression(node: TemplateExpression, head: TemplateLiteralFragment, templateSpans: TemplateSpan[]) {
|
||||
export function updateTemplateExpression(node: TemplateExpression, head: TemplateHead, templateSpans: TemplateSpan[]) {
|
||||
if (node.head !== head || node.templateSpans !== templateSpans) {
|
||||
return updateNode(createTemplateExpression(head, templateSpans, node), node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createYield(asteriskToken: Node, expression: Expression, location?: TextRange) {
|
||||
export function createYield(asteriskToken: AsteriskToken, expression: Expression, location?: TextRange) {
|
||||
const node = <YieldExpression>createNode(SyntaxKind.YieldExpression, location);
|
||||
node.asteriskToken = asteriskToken;
|
||||
node.expression = expression;
|
||||
@ -756,14 +757,14 @@ namespace ts {
|
||||
|
||||
// Misc
|
||||
|
||||
export function createTemplateSpan(expression: Expression, literal: TemplateLiteralFragment, location?: TextRange) {
|
||||
export function createTemplateSpan(expression: Expression, literal: TemplateMiddle | TemplateTail, location?: TextRange) {
|
||||
const node = <TemplateSpan>createNode(SyntaxKind.TemplateSpan, location);
|
||||
node.expression = expression;
|
||||
node.literal = literal;
|
||||
return node;
|
||||
}
|
||||
|
||||
export function updateTemplateSpan(node: TemplateSpan, expression: Expression, literal: TemplateLiteralFragment) {
|
||||
export function updateTemplateSpan(node: TemplateSpan, expression: Expression, literal: TemplateMiddle | TemplateTail) {
|
||||
if (node.expression !== expression || node.literal !== literal) {
|
||||
return updateNode(createTemplateSpan(expression, literal, node), node);
|
||||
}
|
||||
@ -932,14 +933,14 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function updateForOf(node: ForInStatement, initializer: ForInitializer, expression: Expression, statement: Statement) {
|
||||
export function updateForOf(node: ForOfStatement, initializer: ForInitializer, expression: Expression, statement: Statement) {
|
||||
if (node.initializer !== initializer || node.expression !== expression || node.statement !== statement) {
|
||||
return updateNode(createForOf(initializer, expression, statement, node), node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createContinue(label?: Identifier, location?: TextRange): BreakStatement {
|
||||
export function createContinue(label?: Identifier, location?: TextRange): ContinueStatement {
|
||||
const node = <ContinueStatement>createNode(SyntaxKind.ContinueStatement, location);
|
||||
if (label) {
|
||||
node.label = label;
|
||||
@ -1065,7 +1066,7 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createFunctionDeclaration(decorators: Decorator[], modifiers: Modifier[], asteriskToken: Node, name: string | Identifier, typeParameters: TypeParameterDeclaration[], parameters: ParameterDeclaration[], type: TypeNode, body: Block, location?: TextRange, flags?: NodeFlags) {
|
||||
export function createFunctionDeclaration(decorators: Decorator[], modifiers: Modifier[], asteriskToken: AsteriskToken, name: string | Identifier, typeParameters: TypeParameterDeclaration[], parameters: ParameterDeclaration[], type: TypeNode, body: Block, location?: TextRange, flags?: NodeFlags) {
|
||||
const node = <FunctionDeclaration>createNode(SyntaxKind.FunctionDeclaration, location, flags);
|
||||
node.decorators = decorators ? createNodeArray(decorators) : undefined;
|
||||
node.modifiers = modifiers ? createNodeArray(modifiers) : undefined;
|
||||
@ -1560,7 +1561,7 @@ namespace ts {
|
||||
return createParameterDeclaration(
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
createSynthesizedNode(SyntaxKind.DotDotDotToken),
|
||||
createToken(SyntaxKind.DotDotDotToken),
|
||||
name,
|
||||
/*questionToken*/ undefined,
|
||||
/*type*/ undefined,
|
||||
@ -1735,7 +1736,7 @@ namespace ts {
|
||||
|
||||
export function createAwaiterHelper(externalHelpersModuleName: Identifier | undefined, hasLexicalArguments: boolean, promiseConstructor: EntityName | Expression, body: Block) {
|
||||
const generatorFunc = createFunctionExpression(
|
||||
createNode(SyntaxKind.AsteriskToken),
|
||||
createToken(SyntaxKind.AsteriskToken),
|
||||
/*name*/ undefined,
|
||||
/*typeParameters*/ undefined,
|
||||
/*parameters*/ [],
|
||||
|
||||
@ -637,7 +637,7 @@ namespace ts {
|
||||
|
||||
sourceFile.statements = parseList(ParsingContext.SourceElements, parseStatement);
|
||||
Debug.assert(token() === SyntaxKind.EndOfFileToken);
|
||||
sourceFile.endOfFileToken = parseTokenNode();
|
||||
sourceFile.endOfFileToken = <EndOfFileToken>parseTokenNode();
|
||||
|
||||
setExternalModuleIndicator(sourceFile);
|
||||
|
||||
@ -1004,6 +1004,7 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function parseOptionalToken<TKind extends SyntaxKind>(t: TKind): Token<TKind>;
|
||||
function parseOptionalToken(t: SyntaxKind): Node {
|
||||
if (token() === t) {
|
||||
return parseTokenNode();
|
||||
@ -1011,6 +1012,7 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function parseExpectedToken<TKind extends SyntaxKind>(t: TKind, reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, arg0?: any): Token<TKind>;
|
||||
function parseExpectedToken(t: SyntaxKind, reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, arg0?: any): Node {
|
||||
return parseOptionalToken(t) ||
|
||||
createMissingNode(t, reportAtCurrentPosition, diagnosticMessage, arg0);
|
||||
@ -1047,7 +1049,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// note: this function creates only node
|
||||
function createNode(kind: SyntaxKind, pos?: number): Node | Token | Identifier {
|
||||
function createNode<TKind extends SyntaxKind>(kind: TKind, pos?: number): Node | Token<TKind> | Identifier {
|
||||
nodeCount++;
|
||||
if (!(pos >= 0)) {
|
||||
pos = scanner.getStartPos();
|
||||
@ -1920,7 +1922,7 @@ namespace ts {
|
||||
function parseTemplateExpression(): TemplateExpression {
|
||||
const template = <TemplateExpression>createNode(SyntaxKind.TemplateExpression);
|
||||
|
||||
template.head = parseTemplateLiteralFragment();
|
||||
template.head = parseTemplateHead();
|
||||
Debug.assert(template.head.kind === SyntaxKind.TemplateHead, "Template head has wrong token kind");
|
||||
|
||||
const templateSpans = createNodeArray<TemplateSpan>();
|
||||
@ -1940,14 +1942,13 @@ namespace ts {
|
||||
const span = <TemplateSpan>createNode(SyntaxKind.TemplateSpan);
|
||||
span.expression = allowInAnd(parseExpression);
|
||||
|
||||
let literal: TemplateLiteralFragment;
|
||||
|
||||
let literal: TemplateMiddle | TemplateTail;
|
||||
if (token() === SyntaxKind.CloseBraceToken) {
|
||||
reScanTemplateToken();
|
||||
literal = parseTemplateLiteralFragment();
|
||||
literal = parseTemplateMiddleOrTemplateTail();
|
||||
}
|
||||
else {
|
||||
literal = <TemplateLiteralFragment>parseExpectedToken(SyntaxKind.TemplateTail, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.CloseBraceToken));
|
||||
literal = <TemplateTail>parseExpectedToken(SyntaxKind.TemplateTail, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.CloseBraceToken));
|
||||
}
|
||||
|
||||
span.literal = literal;
|
||||
@ -1958,8 +1959,16 @@ namespace ts {
|
||||
return <LiteralExpression>parseLiteralLikeNode(token(), internName);
|
||||
}
|
||||
|
||||
function parseTemplateLiteralFragment(): TemplateLiteralFragment {
|
||||
return <TemplateLiteralFragment>parseLiteralLikeNode(token(), /*internName*/ false);
|
||||
function parseTemplateHead(): TemplateHead {
|
||||
const fragment = parseLiteralLikeNode(token(), /*internName*/ false);
|
||||
Debug.assert(fragment.kind === SyntaxKind.TemplateHead, "Template head has wrong token kind");
|
||||
return <TemplateHead>fragment;
|
||||
}
|
||||
|
||||
function parseTemplateMiddleOrTemplateTail(): TemplateMiddle | TemplateTail {
|
||||
const fragment = parseLiteralLikeNode(token(), /*internName*/ false);
|
||||
Debug.assert(fragment.kind === SyntaxKind.TemplateMiddle || fragment.kind === SyntaxKind.TemplateTail, "Template fragment has wrong token kind");
|
||||
return <TemplateMiddle | TemplateTail>fragment;
|
||||
}
|
||||
|
||||
function parseLiteralLikeNode(kind: SyntaxKind, internName: boolean): LiteralLikeNode {
|
||||
@ -2719,7 +2728,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
let expr = parseAssignmentExpressionOrHigher();
|
||||
let operatorToken: Node;
|
||||
let operatorToken: BinaryOperatorToken;
|
||||
while ((operatorToken = parseOptionalToken(SyntaxKind.CommaToken))) {
|
||||
expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher());
|
||||
}
|
||||
@ -2812,7 +2821,7 @@ namespace ts {
|
||||
// Note: we call reScanGreaterToken so that we get an appropriately merged token
|
||||
// for cases like > > = becoming >>=
|
||||
if (isLeftHandSideExpression(expr) && isAssignmentOperator(reScanGreaterToken())) {
|
||||
return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher());
|
||||
return makeBinaryExpression(expr, <BinaryOperatorToken>parseTokenNode(), parseAssignmentExpressionOrHigher());
|
||||
}
|
||||
|
||||
// It wasn't an assignment or a lambda. This is a conditional expression:
|
||||
@ -3247,7 +3256,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else {
|
||||
leftOperand = makeBinaryExpression(leftOperand, parseTokenNode(), parseBinaryExpressionOrHigher(newPrecedence));
|
||||
leftOperand = makeBinaryExpression(leftOperand, <BinaryOperatorToken>parseTokenNode(), parseBinaryExpressionOrHigher(newPrecedence));
|
||||
}
|
||||
}
|
||||
|
||||
@ -3307,7 +3316,7 @@ namespace ts {
|
||||
return -1;
|
||||
}
|
||||
|
||||
function makeBinaryExpression(left: Expression, operatorToken: Node, right: Expression): BinaryExpression {
|
||||
function makeBinaryExpression(left: Expression, operatorToken: BinaryOperatorToken, right: Expression): BinaryExpression {
|
||||
const node = <BinaryExpression>createNode(SyntaxKind.BinaryExpression, left.pos);
|
||||
node.left = left;
|
||||
node.operatorToken = operatorToken;
|
||||
@ -3324,7 +3333,7 @@ namespace ts {
|
||||
|
||||
function parsePrefixUnaryExpression() {
|
||||
const node = <PrefixUnaryExpression>createNode(SyntaxKind.PrefixUnaryExpression);
|
||||
node.operator = token();
|
||||
node.operator = <PrefixUnaryOperator>token();
|
||||
nextToken();
|
||||
node.operand = parseSimpleUnaryExpression();
|
||||
|
||||
@ -3511,7 +3520,7 @@ namespace ts {
|
||||
function parseIncrementExpression(): IncrementExpression {
|
||||
if (token() === SyntaxKind.PlusPlusToken || token() === SyntaxKind.MinusMinusToken) {
|
||||
const node = <PrefixUnaryExpression>createNode(SyntaxKind.PrefixUnaryExpression);
|
||||
node.operator = token();
|
||||
node.operator = <PrefixUnaryOperator>token();
|
||||
nextToken();
|
||||
node.operand = parseLeftHandSideExpressionOrHigher();
|
||||
return finishNode(node);
|
||||
@ -3527,7 +3536,7 @@ namespace ts {
|
||||
if ((token() === SyntaxKind.PlusPlusToken || token() === SyntaxKind.MinusMinusToken) && !scanner.hasPrecedingLineBreak()) {
|
||||
const node = <PostfixUnaryExpression>createNode(SyntaxKind.PostfixUnaryExpression, expression.pos);
|
||||
node.operand = expression;
|
||||
node.operator = token();
|
||||
node.operator = <PostfixUnaryOperator>token();
|
||||
nextToken();
|
||||
return finishNode(node);
|
||||
}
|
||||
@ -3700,7 +3709,7 @@ namespace ts {
|
||||
badNode.end = invalidElement.end;
|
||||
badNode.left = result;
|
||||
badNode.right = invalidElement;
|
||||
badNode.operatorToken = createMissingNode(SyntaxKind.CommaToken, /*reportAtCurrentPosition*/ false, /*diagnosticMessage*/ undefined);
|
||||
badNode.operatorToken = <BinaryOperatorToken>createMissingNode(SyntaxKind.CommaToken, /*reportAtCurrentPosition*/ false, /*diagnosticMessage*/ undefined);
|
||||
badNode.operatorToken.pos = badNode.operatorToken.end = badNode.right.pos;
|
||||
return <JsxElement><Node>badNode;
|
||||
}
|
||||
@ -3836,7 +3845,7 @@ namespace ts {
|
||||
if (token() === SyntaxKind.EqualsToken) {
|
||||
switch (scanJsxAttributeValue()) {
|
||||
case SyntaxKind.StringLiteral:
|
||||
node.initializer = parseLiteralNode();
|
||||
node.initializer = <StringLiteral>parseLiteralNode();
|
||||
break;
|
||||
default:
|
||||
node.initializer = parseJsxExpression(/*inExpressionContext*/ true);
|
||||
@ -3921,7 +3930,7 @@ namespace ts {
|
||||
const tagExpression = <TaggedTemplateExpression>createNode(SyntaxKind.TaggedTemplateExpression, expression.pos);
|
||||
tagExpression.tag = expression;
|
||||
tagExpression.template = token() === SyntaxKind.NoSubstitutionTemplateLiteral
|
||||
? parseLiteralNode()
|
||||
? <NoSubstitutionTemplateLiteral>parseLiteralNode()
|
||||
: parseTemplateExpression();
|
||||
expression = finishNode(tagExpression);
|
||||
continue;
|
||||
@ -4959,7 +4968,7 @@ namespace ts {
|
||||
return addJSDocComment(finishNode(node));
|
||||
}
|
||||
|
||||
function parseMethodDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: NodeArray<Modifier>, asteriskToken: Node, name: PropertyName, questionToken: Node, diagnosticMessage?: DiagnosticMessage): MethodDeclaration {
|
||||
function parseMethodDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: NodeArray<Modifier>, asteriskToken: AsteriskToken, name: PropertyName, questionToken: QuestionToken, diagnosticMessage?: DiagnosticMessage): MethodDeclaration {
|
||||
const method = <MethodDeclaration>createNode(SyntaxKind.MethodDeclaration, fullStart);
|
||||
method.decorators = decorators;
|
||||
method.modifiers = modifiers;
|
||||
@ -4973,7 +4982,7 @@ namespace ts {
|
||||
return addJSDocComment(finishNode(method));
|
||||
}
|
||||
|
||||
function parsePropertyDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: NodeArray<Modifier>, name: PropertyName, questionToken: Node): ClassElement {
|
||||
function parsePropertyDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: NodeArray<Modifier>, name: PropertyName, questionToken: QuestionToken): ClassElement {
|
||||
const property = <PropertyDeclaration>createNode(SyntaxKind.PropertyDeclaration, fullStart);
|
||||
property.decorators = decorators;
|
||||
property.modifiers = modifiers;
|
||||
@ -5395,7 +5404,7 @@ namespace ts {
|
||||
node.flags |= flags;
|
||||
node.name = parseIdentifier();
|
||||
node.body = parseOptional(SyntaxKind.DotToken)
|
||||
? parseModuleOrNamespaceDeclaration(getNodePos(), /*decorators*/ undefined, /*modifiers*/ undefined, NodeFlags.NestedNamespace | namespaceFlag)
|
||||
? <NamespaceDeclaration>parseModuleOrNamespaceDeclaration(getNodePos(), /*decorators*/ undefined, /*modifiers*/ undefined, NodeFlags.NestedNamespace | namespaceFlag)
|
||||
: parseModuleBlock();
|
||||
return addJSDocComment(finishNode(node));
|
||||
}
|
||||
@ -5574,8 +5583,10 @@ namespace ts {
|
||||
return finishNode(namespaceImport);
|
||||
}
|
||||
|
||||
function parseNamedImportsOrExports(kind: SyntaxKind.NamedImports): NamedImports;
|
||||
function parseNamedImportsOrExports(kind: SyntaxKind.NamedExports): NamedExports;
|
||||
function parseNamedImportsOrExports(kind: SyntaxKind): NamedImportsOrExports {
|
||||
const node = <NamedImports>createNode(kind);
|
||||
const node = <NamedImports | NamedExports>createNode(kind);
|
||||
|
||||
// NamedImports:
|
||||
// { }
|
||||
@ -5585,7 +5596,7 @@ namespace ts {
|
||||
// ImportsList:
|
||||
// ImportSpecifier
|
||||
// ImportsList, ImportSpecifier
|
||||
node.elements = parseBracketedList(ParsingContext.ImportOrExportSpecifiers,
|
||||
node.elements = <NodeArray<ImportSpecifier> | NodeArray<ExportSpecifier>>parseBracketedList(ParsingContext.ImportOrExportSpecifiers,
|
||||
kind === SyntaxKind.NamedImports ? parseImportSpecifier : parseExportSpecifier,
|
||||
SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken);
|
||||
return finishNode(node);
|
||||
@ -5969,14 +5980,15 @@ namespace ts {
|
||||
const parameter = <ParameterDeclaration>createNode(SyntaxKind.Parameter);
|
||||
parameter.type = parseJSDocType();
|
||||
if (parseOptional(SyntaxKind.EqualsToken)) {
|
||||
parameter.questionToken = createNode(SyntaxKind.EqualsToken);
|
||||
// TODO(rbuckton): Can this be changed to SyntaxKind.QuestionToken?
|
||||
parameter.questionToken = <QuestionToken>createNode(SyntaxKind.EqualsToken);
|
||||
}
|
||||
return finishNode(parameter);
|
||||
}
|
||||
|
||||
function parseJSDocTypeReference(): JSDocTypeReference {
|
||||
const result = <JSDocTypeReference>createNode(SyntaxKind.JSDocTypeReference);
|
||||
result.name = parseSimplePropertyName();
|
||||
result.name = <Identifier>parseSimplePropertyName();
|
||||
|
||||
if (token() === SyntaxKind.LessThanToken) {
|
||||
result.typeArguments = parseTypeArguments();
|
||||
@ -6304,7 +6316,7 @@ namespace ts {
|
||||
|
||||
function parseTag(indent: number) {
|
||||
Debug.assert(token() === SyntaxKind.AtToken);
|
||||
const atToken = createNode(SyntaxKind.AtToken, scanner.getTokenPos());
|
||||
const atToken = <AtToken>createNode(SyntaxKind.AtToken, scanner.getTokenPos());
|
||||
atToken.end = scanner.getTextPos();
|
||||
nextJSDocToken();
|
||||
|
||||
@ -6410,7 +6422,7 @@ namespace ts {
|
||||
return comments;
|
||||
}
|
||||
|
||||
function parseUnknownTag(atToken: Node, tagName: Identifier) {
|
||||
function parseUnknownTag(atToken: AtToken, tagName: Identifier) {
|
||||
const result = <JSDocTag>createNode(SyntaxKind.JSDocTag, atToken.pos);
|
||||
result.atToken = atToken;
|
||||
result.tagName = tagName;
|
||||
@ -6440,7 +6452,7 @@ namespace ts {
|
||||
});
|
||||
}
|
||||
|
||||
function parseParamTag(atToken: Node, tagName: Identifier) {
|
||||
function parseParamTag(atToken: AtToken, tagName: Identifier) {
|
||||
let typeExpression = tryParseTypeExpression();
|
||||
skipWhitespace();
|
||||
|
||||
@ -6491,7 +6503,7 @@ namespace ts {
|
||||
return finishNode(result);
|
||||
}
|
||||
|
||||
function parseReturnTag(atToken: Node, tagName: Identifier): JSDocReturnTag {
|
||||
function parseReturnTag(atToken: AtToken, tagName: Identifier): JSDocReturnTag {
|
||||
if (forEach(tags, t => t.kind === SyntaxKind.JSDocReturnTag)) {
|
||||
parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, Diagnostics._0_tag_already_specified, tagName.text);
|
||||
}
|
||||
@ -6503,7 +6515,7 @@ namespace ts {
|
||||
return finishNode(result);
|
||||
}
|
||||
|
||||
function parseTypeTag(atToken: Node, tagName: Identifier): JSDocTypeTag {
|
||||
function parseTypeTag(atToken: AtToken, tagName: Identifier): JSDocTypeTag {
|
||||
if (forEach(tags, t => t.kind === SyntaxKind.JSDocTypeTag)) {
|
||||
parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, Diagnostics._0_tag_already_specified, tagName.text);
|
||||
}
|
||||
@ -6515,7 +6527,7 @@ namespace ts {
|
||||
return finishNode(result);
|
||||
}
|
||||
|
||||
function parsePropertyTag(atToken: Node, tagName: Identifier): JSDocPropertyTag {
|
||||
function parsePropertyTag(atToken: AtToken, tagName: Identifier): JSDocPropertyTag {
|
||||
const typeExpression = tryParseTypeExpression();
|
||||
skipWhitespace();
|
||||
const name = parseJSDocIdentifierName();
|
||||
@ -6533,7 +6545,7 @@ namespace ts {
|
||||
return finishNode(result);
|
||||
}
|
||||
|
||||
function parseTypedefTag(atToken: Node, tagName: Identifier): JSDocTypedefTag {
|
||||
function parseTypedefTag(atToken: AtToken, tagName: Identifier): JSDocTypedefTag {
|
||||
const typeExpression = tryParseTypeExpression();
|
||||
skipWhitespace();
|
||||
|
||||
@ -6555,7 +6567,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
if (!typedefTag.jsDocTypeLiteral) {
|
||||
typedefTag.jsDocTypeLiteral = typeExpression.type;
|
||||
typedefTag.jsDocTypeLiteral = <JSDocTypeLiteral>typeExpression.type;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -6607,7 +6619,7 @@ namespace ts {
|
||||
|
||||
function tryParseChildTag(parentTag: JSDocTypeLiteral): boolean {
|
||||
Debug.assert(token() === SyntaxKind.AtToken);
|
||||
const atToken = createNode(SyntaxKind.AtToken, scanner.getStartPos());
|
||||
const atToken = <AtToken>createNode(SyntaxKind.AtToken, scanner.getStartPos());
|
||||
atToken.end = scanner.getTextPos();
|
||||
nextJSDocToken();
|
||||
|
||||
@ -6637,7 +6649,7 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function parseTemplateTag(atToken: Node, tagName: Identifier): JSDocTemplateTag {
|
||||
function parseTemplateTag(atToken: AtToken, tagName: Identifier): JSDocTemplateTag {
|
||||
if (forEach(tags, t => t.kind === SyntaxKind.JSDocTemplateTag)) {
|
||||
parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, Diagnostics._0_tag_already_specified, tagName.text);
|
||||
}
|
||||
|
||||
@ -220,7 +220,7 @@ namespace ts {
|
||||
|
||||
function flattenDestructuring(
|
||||
context: TransformationContext,
|
||||
root: BindingElement | BinaryExpression,
|
||||
root: VariableDeclaration | ParameterDeclaration | BindingElement | BinaryExpression,
|
||||
value: Expression,
|
||||
location: TextRange,
|
||||
emitAssignment: (name: Identifier, value: Expression, location: TextRange, original: Node) => void,
|
||||
@ -320,7 +320,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function emitBindingElement(target: BindingElement, value: Expression) {
|
||||
function emitBindingElement(target: VariableDeclaration | ParameterDeclaration | BindingElement, value: Expression) {
|
||||
// Any temporary assignments needed to emit target = value should point to target
|
||||
const initializer = visitor ? visitNode(target.initializer, visitor, isExpression) : target.initializer;
|
||||
if (initializer) {
|
||||
|
||||
@ -982,7 +982,7 @@ namespace ts {
|
||||
if (statementOffset < ctorStatements.length) {
|
||||
firstStatement = ctorStatements[statementOffset];
|
||||
|
||||
if (firstStatement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((firstStatement as ExpressionStatement).expression)) {
|
||||
if (firstStatement.kind === SyntaxKind.ExpressionStatement && isSuperCall((firstStatement as ExpressionStatement).expression)) {
|
||||
const superCall = (firstStatement as ExpressionStatement).expression as CallExpression;
|
||||
superCallExpression = setOriginalNode(
|
||||
saveStateAndInvoke(superCall, visitImmediateSuperCallInBody),
|
||||
@ -3198,7 +3198,7 @@ namespace ts {
|
||||
* @param node The declaration.
|
||||
* @param allowComments Allow comments for the name.
|
||||
*/
|
||||
function getDeclarationName(node: DeclarationStatement | ClassExpression, allowComments?: boolean, allowSourceMaps?: boolean, emitFlags?: EmitFlags) {
|
||||
function getDeclarationName(node: ClassDeclaration | ClassExpression | FunctionDeclaration, allowComments?: boolean, allowSourceMaps?: boolean, emitFlags?: EmitFlags) {
|
||||
if (node.name && !isGeneratedIdentifier(node.name)) {
|
||||
const name = getMutableClone(node.name);
|
||||
emitFlags |= getEmitFlags(node.name);
|
||||
|
||||
@ -528,7 +528,7 @@ namespace ts {
|
||||
*
|
||||
* @param node The node to visit.
|
||||
*/
|
||||
function visitAccessorDeclaration(node: GetAccessorDeclaration) {
|
||||
function visitAccessorDeclaration(node: AccessorDeclaration) {
|
||||
const savedInGeneratorFunctionBody = inGeneratorFunctionBody;
|
||||
const savedInStatementContainingYield = inStatementContainingYield;
|
||||
inGeneratorFunctionBody = false;
|
||||
@ -660,12 +660,12 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isCompoundAssignment(kind: SyntaxKind) {
|
||||
function isCompoundAssignment(kind: BinaryOperator): kind is CompoundAssignmentOperator {
|
||||
return kind >= SyntaxKind.FirstCompoundAssignment
|
||||
&& kind <= SyntaxKind.LastCompoundAssignment;
|
||||
}
|
||||
|
||||
function getOperatorForCompoundAssignment(kind: SyntaxKind) {
|
||||
function getOperatorForCompoundAssignment(kind: CompoundAssignmentOperator): BitwiseOperatorOrHigher {
|
||||
switch (kind) {
|
||||
case SyntaxKind.PlusEqualsToken: return SyntaxKind.PlusToken;
|
||||
case SyntaxKind.MinusEqualsToken: return SyntaxKind.MinusToken;
|
||||
|
||||
@ -599,7 +599,7 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
statements.push(
|
||||
createExportStatement(node.name, setEmitFlags(getSynthesizedClone(node.name), EmitFlags.LocalName), /*location*/ node)
|
||||
createExportStatement(<Identifier>node.name, setEmitFlags(getSynthesizedClone(node.name), EmitFlags.LocalName), /*location*/ node)
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -796,7 +796,7 @@ namespace ts {
|
||||
addVarForExportedEnumOrNamespaceDeclaration(statements, original);
|
||||
}
|
||||
|
||||
addExportMemberAssignments(statements, original.name);
|
||||
addExportMemberAssignments(statements, <Identifier>original.name);
|
||||
|
||||
return statements;
|
||||
}
|
||||
@ -819,7 +819,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getDeclarationName(node: DeclarationStatement) {
|
||||
return node.name ? getSynthesizedClone(node.name) : getGeneratedNameForNode(node);
|
||||
return node.name ? getSynthesizedClone(<Identifier>node.name) : getGeneratedNameForNode(node);
|
||||
}
|
||||
|
||||
function onEmitNode(emitContext: EmitContext, node: Node, emitCallback: (emitContext: EmitContext, node: Node) => void): void {
|
||||
@ -916,7 +916,7 @@ namespace ts {
|
||||
if (node.kind === SyntaxKind.PostfixUnaryExpression) {
|
||||
transformedUnaryExpression = createBinary(
|
||||
operand,
|
||||
createNode(operator === SyntaxKind.PlusPlusToken ? SyntaxKind.PlusEqualsToken : SyntaxKind.MinusEqualsToken),
|
||||
createToken(operator === SyntaxKind.PlusPlusToken ? SyntaxKind.PlusEqualsToken : SyntaxKind.MinusEqualsToken),
|
||||
createLiteral(1),
|
||||
/*location*/ node
|
||||
);
|
||||
|
||||
@ -1201,7 +1201,7 @@ namespace ts {
|
||||
* @param node The declaration statement.
|
||||
*/
|
||||
function getDeclarationName(node: DeclarationStatement) {
|
||||
return node.name ? getSynthesizedClone(node.name) : getGeneratedNameForNode(node);
|
||||
return node.name ? getSynthesizedClone(<Identifier>node.name) : getGeneratedNameForNode(node);
|
||||
}
|
||||
|
||||
function addExportStarFunction(statements: Statement[], localNames: Identifier) {
|
||||
|
||||
@ -989,7 +989,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
const statement = statements[index];
|
||||
if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((<ExpressionStatement>statement).expression)) {
|
||||
if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCall((<ExpressionStatement>statement).expression)) {
|
||||
result.push(visitNode(statement, visitor, isStatement));
|
||||
return index + 1;
|
||||
}
|
||||
@ -3100,7 +3100,7 @@ namespace ts {
|
||||
return createStatement(expression, /*location*/ undefined);
|
||||
}
|
||||
|
||||
function addExportMemberAssignment(statements: Statement[], node: DeclarationStatement) {
|
||||
function addExportMemberAssignment(statements: Statement[], node: ClassDeclaration | FunctionDeclaration) {
|
||||
const expression = createAssignment(
|
||||
getExportName(node),
|
||||
getLocalName(node, /*noSourceMaps*/ true)
|
||||
@ -3178,7 +3178,7 @@ namespace ts {
|
||||
* @param noSourceMaps A value indicating whether source maps may not be emitted for the name.
|
||||
* @param allowComments A value indicating whether comments may be emitted for the name.
|
||||
*/
|
||||
function getLocalName(node: DeclarationStatement | ClassExpression, noSourceMaps?: boolean, allowComments?: boolean) {
|
||||
function getLocalName(node: FunctionDeclaration | ClassDeclaration | ClassExpression | ModuleDeclaration | EnumDeclaration, noSourceMaps?: boolean, allowComments?: boolean) {
|
||||
return getDeclarationName(node, allowComments, !noSourceMaps, EmitFlags.LocalName);
|
||||
}
|
||||
|
||||
@ -3192,7 +3192,7 @@ namespace ts {
|
||||
* @param noSourceMaps A value indicating whether source maps may not be emitted for the name.
|
||||
* @param allowComments A value indicating whether comments may be emitted for the name.
|
||||
*/
|
||||
function getExportName(node: DeclarationStatement | ClassExpression, noSourceMaps?: boolean, allowComments?: boolean) {
|
||||
function getExportName(node: FunctionDeclaration | ClassDeclaration | ClassExpression | ModuleDeclaration | EnumDeclaration, noSourceMaps?: boolean, allowComments?: boolean) {
|
||||
if (isNamespaceExport(node)) {
|
||||
return getNamespaceMemberName(getDeclarationName(node), allowComments, !noSourceMaps);
|
||||
}
|
||||
@ -3208,9 +3208,9 @@ namespace ts {
|
||||
* @param allowSourceMaps A value indicating whether source maps may be emitted for the name.
|
||||
* @param emitFlags Additional NodeEmitFlags to specify for the name.
|
||||
*/
|
||||
function getDeclarationName(node: DeclarationStatement | ClassExpression, allowComments?: boolean, allowSourceMaps?: boolean, emitFlags?: EmitFlags) {
|
||||
function getDeclarationName(node: FunctionDeclaration | ClassDeclaration | ClassExpression | ModuleDeclaration | EnumDeclaration, allowComments?: boolean, allowSourceMaps?: boolean, emitFlags?: EmitFlags) {
|
||||
if (node.name) {
|
||||
const name = getMutableClone(node.name);
|
||||
const name = getMutableClone(<Identifier>node.name);
|
||||
emitFlags |= getEmitFlags(node.name);
|
||||
if (!allowSourceMaps) {
|
||||
emitFlags |= EmitFlags.NoSourceMap;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -609,7 +609,7 @@ namespace ts {
|
||||
return !!(getCombinedNodeFlags(node) & NodeFlags.Let);
|
||||
}
|
||||
|
||||
export function isSuperCallExpression(n: Node): boolean {
|
||||
export function isSuperCall(n: Node): n is SuperCall {
|
||||
return n.kind === SyntaxKind.CallExpression && (<CallExpression>n).expression.kind === SyntaxKind.SuperKeyword;
|
||||
}
|
||||
|
||||
@ -1047,7 +1047,7 @@ namespace ts {
|
||||
/**
|
||||
* Determines whether a node is a property or element access expression for super.
|
||||
*/
|
||||
export function isSuperProperty(node: Node): node is (PropertyAccessExpression | ElementAccessExpression) {
|
||||
export function isSuperProperty(node: Node): node is SuperProperty {
|
||||
const kind = node.kind;
|
||||
return (kind === SyntaxKind.PropertyAccessExpression || kind === SyntaxKind.ElementAccessExpression)
|
||||
&& (<PropertyAccessExpression | ElementAccessExpression>node).expression.kind === SyntaxKind.SuperKeyword;
|
||||
@ -1375,7 +1375,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function getNamespaceDeclarationNode(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration) {
|
||||
export function getNamespaceDeclarationNode(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration): ImportEqualsDeclaration | NamespaceImport {
|
||||
if (node.kind === SyntaxKind.ImportEqualsDeclaration) {
|
||||
return <ImportEqualsDeclaration>node;
|
||||
}
|
||||
@ -2459,7 +2459,7 @@ namespace ts {
|
||||
return file.moduleName || getExternalModuleNameFromPath(host, file.fileName);
|
||||
}
|
||||
|
||||
export function getExternalModuleNameFromDeclaration(host: EmitHost, resolver: EmitResolver, declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration): string {
|
||||
export function getExternalModuleNameFromDeclaration(host: EmitHost, resolver: EmitResolver, declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration): string {
|
||||
const file = resolver.getExternalModuleFileFromDeclaration(declaration);
|
||||
if (!file || isDeclarationFile(file)) {
|
||||
return undefined;
|
||||
@ -3625,14 +3625,14 @@ namespace ts {
|
||||
return SyntaxKind.FirstTemplateToken <= kind && kind <= SyntaxKind.LastTemplateToken;
|
||||
}
|
||||
|
||||
function isTemplateLiteralFragmentKind(kind: SyntaxKind) {
|
||||
return kind === SyntaxKind.TemplateHead
|
||||
|| kind === SyntaxKind.TemplateMiddle
|
||||
|| kind === SyntaxKind.TemplateTail;
|
||||
export function isTemplateHead(node: Node): node is TemplateHead {
|
||||
return node.kind === SyntaxKind.TemplateHead;
|
||||
}
|
||||
|
||||
export function isTemplateLiteralFragment(node: Node): node is TemplateLiteralFragment {
|
||||
return isTemplateLiteralFragmentKind(node.kind);
|
||||
export function isTemplateMiddleOrTemplateTail(node: Node): node is TemplateMiddle | TemplateTail {
|
||||
const kind = node.kind;
|
||||
return kind === SyntaxKind.TemplateMiddle
|
||||
|| kind === SyntaxKind.TemplateTail;
|
||||
}
|
||||
|
||||
// Identifiers
|
||||
@ -3797,7 +3797,7 @@ namespace ts {
|
||||
return node.kind === SyntaxKind.CallExpression;
|
||||
}
|
||||
|
||||
export function isTemplate(node: Node): node is Template {
|
||||
export function isTemplateLiteral(node: Node): node is TemplateLiteral {
|
||||
const kind = node.kind;
|
||||
return kind === SyntaxKind.TemplateExpression
|
||||
|| kind === SyntaxKind.NoSubstitutionTemplateLiteral;
|
||||
|
||||
@ -799,7 +799,7 @@ namespace ts {
|
||||
case SyntaxKind.TaggedTemplateExpression:
|
||||
return updateTaggedTemplate(<TaggedTemplateExpression>node,
|
||||
visitNode((<TaggedTemplateExpression>node).tag, visitor, isExpression),
|
||||
visitNode((<TaggedTemplateExpression>node).template, visitor, isTemplate));
|
||||
visitNode((<TaggedTemplateExpression>node).template, visitor, isTemplateLiteral));
|
||||
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
return updateParen(<ParenthesizedExpression>node,
|
||||
@ -862,7 +862,7 @@ namespace ts {
|
||||
|
||||
case SyntaxKind.TemplateExpression:
|
||||
return updateTemplateExpression(<TemplateExpression>node,
|
||||
visitNode((<TemplateExpression>node).head, visitor, isTemplateLiteralFragment),
|
||||
visitNode((<TemplateExpression>node).head, visitor, isTemplateHead),
|
||||
visitNodes((<TemplateExpression>node).templateSpans, visitor, isTemplateSpan));
|
||||
|
||||
case SyntaxKind.YieldExpression:
|
||||
@ -890,7 +890,7 @@ namespace ts {
|
||||
case SyntaxKind.TemplateSpan:
|
||||
return updateTemplateSpan(<TemplateSpan>node,
|
||||
visitNode((<TemplateSpan>node).expression, visitor, isExpression),
|
||||
visitNode((<TemplateSpan>node).literal, visitor, isTemplateLiteralFragment));
|
||||
visitNode((<TemplateSpan>node).literal, visitor, isTemplateMiddleOrTemplateTail));
|
||||
|
||||
// Element
|
||||
case SyntaxKind.Block:
|
||||
|
||||
@ -175,7 +175,7 @@ namespace ts.formatting {
|
||||
return rangeContainsRange((<InterfaceDeclaration>parent).members, node);
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
const body = (<ModuleDeclaration>parent).body;
|
||||
return body && body.kind === SyntaxKind.Block && rangeContainsRange((<Block>body).statements, node);
|
||||
return body && body.kind === SyntaxKind.ModuleBlock && rangeContainsRange((<ModuleBlock>body).statements, node);
|
||||
case SyntaxKind.SourceFile:
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
|
||||
@ -332,7 +332,7 @@ namespace ts.formatting {
|
||||
(<CallExpression>node.parent).expression !== node) {
|
||||
|
||||
const fullCallOrNewExpression = (<CallExpression | NewExpression>node.parent).expression;
|
||||
const startingExpression = getStartingExpression(<PropertyAccessExpression | CallExpression | ElementAccessExpression>fullCallOrNewExpression);
|
||||
const startingExpression = getStartingExpression(fullCallOrNewExpression);
|
||||
|
||||
if (fullCallOrNewExpression === startingExpression) {
|
||||
return Value.Unknown;
|
||||
@ -350,15 +350,14 @@ namespace ts.formatting {
|
||||
|
||||
return Value.Unknown;
|
||||
|
||||
function getStartingExpression(node: PropertyAccessExpression | CallExpression | ElementAccessExpression) {
|
||||
function getStartingExpression(node: Expression) {
|
||||
while (true) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.CallExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
case SyntaxKind.ElementAccessExpression:
|
||||
|
||||
node = <PropertyAccessExpression | CallExpression | ElementAccessExpression | PropertyAccessExpression>node.expression;
|
||||
node = (<PropertyAccessExpression | CallExpression | NewExpression | ElementAccessExpression | PropertyAccessExpression>node).expression;
|
||||
break;
|
||||
default:
|
||||
return node;
|
||||
|
||||
@ -29,9 +29,9 @@ namespace ts {
|
||||
/** The version of the language service API */
|
||||
export const servicesVersion = "0.5";
|
||||
|
||||
function createNode(kind: SyntaxKind, pos: number, end: number, parent?: Node): NodeObject | TokenObject | IdentifierObject {
|
||||
function createNode<TKind extends SyntaxKind>(kind: TKind, pos: number, end: number, parent?: Node): NodeObject | TokenObject<TKind> | IdentifierObject {
|
||||
const node = kind >= SyntaxKind.FirstNode ? new NodeObject(kind, pos, end) :
|
||||
kind === SyntaxKind.Identifier ? new IdentifierObject(kind, pos, end) :
|
||||
kind === SyntaxKind.Identifier ? new IdentifierObject(SyntaxKind.Identifier, pos, end) :
|
||||
new TokenObject(kind, pos, end);
|
||||
node.parent = parent;
|
||||
return node;
|
||||
@ -210,14 +210,13 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
class TokenOrIdentifierObject implements Token {
|
||||
class TokenOrIdentifierObject implements Node {
|
||||
public kind: SyntaxKind;
|
||||
public pos: number;
|
||||
public end: number;
|
||||
public flags: NodeFlags;
|
||||
public parent: Node;
|
||||
public jsDocComments: JSDoc[];
|
||||
public __tokenTag: any;
|
||||
|
||||
constructor(pos: number, end: number) {
|
||||
// Set properties in same order as NodeObject
|
||||
@ -319,16 +318,25 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
class TokenObject extends TokenOrIdentifierObject {
|
||||
public kind: SyntaxKind;
|
||||
constructor(kind: SyntaxKind, pos: number, end: number) {
|
||||
class TokenObject<TKind extends SyntaxKind> extends TokenOrIdentifierObject implements Token<TKind> {
|
||||
public kind: TKind;
|
||||
|
||||
constructor(kind: TKind, pos: number, end: number) {
|
||||
super(pos, end);
|
||||
this.kind = kind;
|
||||
}
|
||||
}
|
||||
|
||||
class IdentifierObject extends TokenOrIdentifierObject {
|
||||
constructor(kind: SyntaxKind, pos: number, end: number) {
|
||||
class IdentifierObject extends TokenOrIdentifierObject implements Identifier {
|
||||
public kind: SyntaxKind.Identifier;
|
||||
public text: string;
|
||||
_primaryExpressionBrand: any;
|
||||
_memberExpressionBrand: any;
|
||||
_leftHandSideExpressionBrand: any;
|
||||
_incrementExpressionBrand: any;
|
||||
_unaryExpressionBrand: any;
|
||||
_expressionBrand: any;
|
||||
constructor(kind: SyntaxKind.Identifier, pos: number, end: number) {
|
||||
super(pos, end);
|
||||
}
|
||||
}
|
||||
@ -424,6 +432,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
class SourceFileObject extends NodeObject implements SourceFile {
|
||||
public kind: SyntaxKind.SourceFile;
|
||||
public _declarationBrand: any;
|
||||
public fileName: string;
|
||||
public path: Path;
|
||||
@ -432,7 +441,7 @@ namespace ts {
|
||||
public lineMap: number[];
|
||||
|
||||
public statements: NodeArray<Statement>;
|
||||
public endOfFileToken: Node;
|
||||
public endOfFileToken: Token<SyntaxKind.EndOfFileToken>;
|
||||
|
||||
public amdDependencies: { name: string; path: string }[];
|
||||
public moduleName: string;
|
||||
|
||||
@ -114,12 +114,12 @@ namespace ts.SymbolDisplay {
|
||||
}
|
||||
|
||||
// try get the call/construct signature from the type if it matches
|
||||
let callExpression: CallExpression;
|
||||
let callExpression: CallExpression | NewExpression;
|
||||
if (location.kind === SyntaxKind.CallExpression || location.kind === SyntaxKind.NewExpression) {
|
||||
callExpression = <CallExpression>location;
|
||||
callExpression = <CallExpression | NewExpression>location;
|
||||
}
|
||||
else if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) {
|
||||
callExpression = <CallExpression>location.parent;
|
||||
callExpression = <CallExpression | NewExpression>location.parent;
|
||||
}
|
||||
|
||||
if (callExpression) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user