diff --git a/scripts/processTypes.ts b/scripts/processTypes.ts index 0aa79047d93..e1c676d8ee9 100644 --- a/scripts/processTypes.ts +++ b/scripts/processTypes.ts @@ -12,6 +12,7 @@ import { getSymbolId, getProperty, hasProperty, + createSourceFile, map, SyntaxKind, CompilerOptions, @@ -24,6 +25,7 @@ import { SourceFile, Declaration, ModuleDeclaration, + ModuleBlock, InterfaceDeclaration, TypeAliasDeclaration, EnumDeclaration, @@ -33,6 +35,15 @@ import { TypeReferenceNode, UnionTypeNode, ExpressionWithTypeArguments, + ExpressionStatement, + Expression, + CallExpression, + PropertyAccessExpression, + ObjectLiteralExpression, + ArrayLiteralExpression, + PropertyAssignment, + LiteralExpression, + Identifier, SymbolFlags, Symbol, SymbolTable, @@ -48,6 +59,7 @@ interface SyntaxNode { kindName?: string; typeName?: string; members?: SyntaxMember[]; + options?: KindOptions; } interface SyntaxMember { @@ -85,14 +97,21 @@ interface FactoryParamAnnotation extends Annotation { propertyName?: string; } +interface KindOptions { + create: boolean; + update: boolean; + test: boolean; +} + interface KindAnnotation extends Annotation { kind: SyntaxKind; + options: KindOptions; } const columnWrap = 150; const emptyArray: any[] = []; const kindPattern = /@kind\s*\(\s*SyntaxKind\.(\w+)\s*\)/g; -const annotationPattern = /@(\w+)\s*(\([^)]*\))?/g; +const annotationPattern = /@(\w+\s*[^\r\n]*)/g; const annotationArgumentPattern = /[(,]([^,)]+)/g; const whitespacePattern = /\s/; const quotePattern = /["'`]/; @@ -104,7 +123,6 @@ let host: CompilerHost; let program: Program; let checker: TypeChecker; let sourceFile: SourceFile; -let writer: EmitTextWriter; let tsModuleSymbol: Symbol; let nodeSymbol: Symbol; let nodeArraySymbol: Symbol; @@ -113,6 +131,9 @@ let syntaxKindSymbol: Symbol; let syntaxKindValueToSymbol: Symbol[] = []; let nodeAnnotations: Annotation[][] = []; let syntax: SyntaxNode[] = []; +let syntaxKindTypeUsages: Map = {}; +let memberTypeUsages: Map = {}; +let memberTypeUsageRedirects: Map = {}; main(); @@ -133,8 +154,8 @@ function main() { discover(); let inputDirectory = sys.resolvePath(combinePaths(file, "..")); - let output = combinePaths(inputDirectory, "factory.generated.ts"); - generate(output); + let factoryOutputFile = combinePaths(inputDirectory, "factory.generated.ts"); + generateFactory(factoryOutputFile); } /** @@ -147,6 +168,12 @@ function discover() { syntax.sort((a, b) => { return a.kind - b.kind; }); + // Set up member type usage redirects for types with a single kind + for (let typeName in syntaxKindTypeUsages) { + if (syntaxKindTypeUsages[typeName].length === 1) { + memberTypeUsageRedirects[typeName] = syntaxKindTypeUsages[typeName][0].name; + } + } function visit(node: Node) { switch (node.kind) { @@ -231,16 +258,18 @@ function discover() { } } - function createSyntaxNodes(decl: InterfaceDeclaration | TypeAliasDeclaration, symbol: Symbol, kinds: SyntaxKind[]) { + function createSyntaxNodes(decl: InterfaceDeclaration | TypeAliasDeclaration, symbol: Symbol, kinds: KindAnnotation[]) { if (getFactoryHiddenStateForSymbol(symbol) === FactoryHiddenState.Hidden) { return; } let symbolOrder = getFactoryOrder(symbol, /*inherited*/ true); - for (let kind of kinds) { - let type = checker.getDeclaredTypeOfSymbol(symbol); + for (let kindAnnotation of kinds) { + let kind = kindAnnotation.kind; let kindSymbol = syntaxKindValueToSymbol[kind]; + recordTypeUsagesForKind(kindSymbol, symbol); let kindOrder = getFactoryOrder(kindSymbol, /*inherited*/ false); + let type = checker.getDeclaredTypeOfSymbol(symbol); var members: SyntaxMember[] = []; for (let property of checker.getPropertiesOfType(type)) { // Skip any hidden properties @@ -255,16 +284,21 @@ function discover() { let propertyIsNodeArray = typeNode && isNodeArray(typeNode); let propertyIsModifiersArray = typeNode && isModifiersArray(typeNode); if (propertyIsFactoryParam || propertyIsNodeArray || propertyIsModifiersArray || propertyIsNode) { + let typeName = typeNode ? normalizeTypeName(typeNode.getText()) : "any"; + let elementTypeName = propertyIsNodeArray ? (typeNode).typeArguments[0].getText() : undefined; members.push({ propertyName: property.name, paramName: property.name === "arguments" ? "_arguments" : property.name, - typeName: typeNode ? typeNode.getText() : "any", - elementTypeName: propertyIsNodeArray ? (typeNode).typeArguments[0].getText() : undefined, + typeName: typeName, + elementTypeName: elementTypeName, isFactoryParam: propertyIsFactoryParam, isNodeArray: propertyIsNodeArray, isModifiersArray: propertyIsModifiersArray, isNode: propertyIsNode }); + if (!propertyIsFactoryParam && (propertyIsNodeArray || propertyIsNode)) { + recordTypeUsageForMember(propertyIsNode ? typeName : elementTypeName); + } } } @@ -295,345 +329,52 @@ function discover() { kind, kindName: kindSymbol.name, typeName: symbol.name, - members + members, + options: kindAnnotation.options }); } } + function recordTypeUsagesForKind(kindSymbol: Symbol, typeSymbol: Symbol) { + memberTypeUsages[kindSymbol.name] = false; + recordTypeUsagesForKindWorker(kindSymbol, typeSymbol); + } + + function recordTypeUsagesForKindWorker(kindSymbol: Symbol, typeSymbol: Symbol) { + let usages = syntaxKindTypeUsages[typeSymbol.name]; + if (!usages) { + syntaxKindTypeUsages[typeSymbol.name] = usages = []; + } + + if (usages.indexOf(kindSymbol) === -1) { + usages.push(kindSymbol); + } + + for (let superType of getSuperTypes(typeSymbol.declarations[0])) { + recordTypeUsagesForKindWorker(kindSymbol, superType); + } + } + + function recordTypeUsageForMember(typeName: string) { + if (!hasProperty(memberTypeUsages, typeName)) { + memberTypeUsages[typeName] = true; + } + } + + function normalizeTypeName(typeName: string) { + let parts = typeName.split(/\s*\|\s*/g); + if (parts.length === 0) { + return parts[0]; + } + + parts.sort(); + return parts.join(" | "); + } + function getTypeNodeForProperty(property: Symbol) { return (property.declarations[0]).type; } - function isTypeReferenceNode(node: Node): node is TypeReferenceNode { - return node ? node.kind === SyntaxKind.TypeReference : false; - } - - function isUnionTypeNode(node: Node): node is UnionTypeNode { - return node ? node.kind === SyntaxKind.UnionType : false; - } - - function isInterfaceDeclaration(node: Node): node is InterfaceDeclaration { - return node ? node.kind === SyntaxKind.InterfaceDeclaration : false; - } - - function isTypeAliasDeclaration(node: Node): node is TypeAliasDeclaration { - return node ? node.kind === SyntaxKind.TypeAliasDeclaration : false; - } - - function isExpressionWithTypeArguments(node: Node): node is ExpressionWithTypeArguments { - return node ? node.kind === SyntaxKind.ExpressionWithTypeArguments : false; - } - - function isNodeArray(typeNode: TypeNode): boolean { - return isTypeReferenceNode(typeNode) ? checker.getSymbolAtLocation(typeNode.typeName) === nodeArraySymbol : false; - } - - function isModifiersArray(typeNode: TypeNode): boolean { - return isTypeReferenceNode(typeNode) ? checker.getSymbolAtLocation(typeNode.typeName) === modifiersArraySymbol : false; - } - - function getSuperTypes(node: Declaration) { - let superTypes: Symbol[] = []; - let superTypeSymbolSet: boolean[] = []; - - if (isTypeAliasDeclaration(node)) { - fillSuperTypes(node.type); - } - else if (isInterfaceDeclaration(node) && node.heritageClauses) { - for (let superType of node.heritageClauses[0].types) { - fillSuperTypes(superType); - } - } - - return superTypes; - - function fillSuperTypes(node: TypeNode) { - if (isUnionTypeNode(node)) { - // Flatten union types - for (let constituentType of node.types) { - fillSuperTypes(constituentType); - } - } - else { - // Add type references - let symbol = isTypeReferenceNode(node) ? checker.getSymbolAtLocation(node.typeName) - : isExpressionWithTypeArguments(node) ? checker.getSymbolAtLocation(node.expression) - : undefined; - - if (symbol) { - if (superTypeSymbolSet[getSymbolId(symbol)]) { - return; - } - - superTypeSymbolSet[getSymbolId(symbol)] = true; - superTypes.push(symbol); - } - } - } - } - - function isSubtypeOf(node: TypeNode | Declaration, superTypeSymbol: Symbol): boolean { - if (isInterfaceDeclaration(node)) { - if (node.heritageClauses) { - for (let superType of node.heritageClauses[0].types) { - if (isSubtypeOf(superType, superTypeSymbol)) { - return true; - } - } - } - } - else if (isTypeAliasDeclaration(node)) { - return isSubtypeOf(node.type, superTypeSymbol); - } - else if (isUnionTypeNode(node)) { - for (let constituentType of node.types) { - if (isSubtypeOf(constituentType, superTypeSymbol)) { - return true; - } - } - } - else { - let typeSymbol = isTypeReferenceNode(node) ? checker.getSymbolAtLocation(node.typeName) - : isExpressionWithTypeArguments(node) ? checker.getSymbolAtLocation(node.expression) - : undefined; - - if (!typeSymbol) { - return false; - } - else if (typeSymbol === superTypeSymbol) { - return true; - } - - return isSubtypeOf(typeSymbol.declarations[0], superTypeSymbol); - } - - return false; - } - - function findAnnotation(symbol: Symbol, match: (annotation: Annotation) => boolean): TAnnotation { - for (let decl of symbol.declarations) { - for (let annotation of getAnnotationsForNode(decl)) { - if (match(annotation)) { - return annotation; - } - } - } - - return undefined; - } - - function matchAnnotations(symbol: Symbol, match: (annotation: Annotation) => boolean): TAnnotation[] { - let annotations: TAnnotation[]; - for (let decl of symbol.declarations) { - for (let annotation of getAnnotationsForNode(decl)) { - if (match(annotation)) { - if (!annotations) { - annotations = []; - } - - annotations.push(annotation); - } - } - } - - return annotations || emptyArray; - } - - function getAnnotations(symbol: Symbol): Annotation[] { - let annotations: Annotation[]; - for (let decl of symbol.declarations) { - let declAnnotations = getAnnotationsForNode(decl); - if (declAnnotations !== emptyArray) { - if (!annotations) { - annotations = []; - } - for (let annotation of declAnnotations) { - annotations.push(annotation); - } - } - } - return annotations; - } - - function getAnnotationsForNode(node: Node): Annotation[] { - let annotations = nodeAnnotations[getNodeId(node)]; - if (annotations) { - return annotations; - } - - let leadingCommentRanges = getLeadingCommentRanges(sourceFile.text, node.pos); - if (leadingCommentRanges) { - for (let range of leadingCommentRanges) { - parseAnnotations(range); - } - } - - if (!annotations) { - annotations = emptyArray; - } - - nodeAnnotations[getNodeId(node)] = annotations; - return annotations; - - function parseAnnotations(range: CommentRange) { - let text = sourceFile.text; - let comment = text.substring(range.pos, range.end); - let annotationMatch: RegExpExecArray; - while (annotationMatch = annotationPattern.exec(comment)) { - let name = annotationMatch[1]; - let _arguments: (string | number | boolean)[] = []; - if (annotationMatch[2]) { - let argumentMatch: RegExpExecArray; - let unterminatedStringLiteral: string; - let quoteToken: string; - while (argumentMatch = annotationArgumentPattern.exec(annotationMatch[2].trim())) { - let argumentText = argumentMatch[1]; - let pos = 0; - let end = argumentText.length - 1; - let ch: string; - if (unterminatedStringLiteral) { - unterminatedStringLiteral += ","; - while (end >= 0 && whitespacePattern.test(ch = argumentText.charAt(end))) { - end--; - } - - if (ch === quoteToken) { - if (end > 0) { - unterminatedStringLiteral += argumentText.substring(0, end); - } - - _arguments.push(unterminatedStringLiteral); - unterminatedStringLiteral = undefined; - quoteToken = undefined; - } - else { - unterminatedStringLiteral += "," + argumentText; - } - - continue; - } - - while (pos <= end && whitespacePattern.test(ch = argumentText.charAt(pos))) { - pos++; - } - - while (end >= pos && whitespacePattern.test(argumentText.charAt(end))) { - end--; - } - - if (end < pos || end < 0) { - _arguments.push(undefined); - continue; - } - - if (isQuote(ch)) { - if (argumentText.charAt(end) === ch) { - _arguments.push(argumentText.substring(pos + 1, end)); - } - else { - quoteToken = ch; - unterminatedStringLiteral = argumentText.substring(pos + 1); - } - - continue; - } - - argumentText = argumentText.substring(pos, end + 1); - if (argumentText === "null") { - _arguments.push(null); - } - else if (argumentText === "undefined") { - _arguments.push(undefined); - } - else if (argumentText === "true") { - _arguments.push(true); - } - else if (argumentText === "false") { - _arguments.push(false); - } - else if (numberPattern.test(argumentText)) { - _arguments.push(Number(argumentText)); - } - else { - _arguments.push(getConstantValue(node, argumentText)); - } - } - } - - if (!annotations) { - annotations = []; - } - - annotations.push(createAnnotation(name, _arguments)); - } - } - } - - function getSymbol(symbols: SymbolTable, name: string, meaning: SymbolFlags) { - if (symbols && meaning && hasProperty(symbols, name)) { - let symbol = symbols[name]; - if (symbol.flags & meaning) { - return symbol; - } - } - - return undefined; - } - - function resolveName(location: Node, name: string, meaning: SymbolFlags) { - let symbols = checker.getSymbolsInScope(location, meaning); - for (let symbol of symbols) { - if (symbol.name === name) { - return symbol; - } - } - - return undefined; - } - - function getConstantValue(location: Node, name: string) { - let qn = name.split("."); - if (qn.length === 1) { - return undefined; - } - - let namespace: Symbol; - if (qn.length > 2) { - for (let i = 0; i < qn.length - 2; i++) { - namespace = i === 0 - ? resolveName(location, qn[i], SymbolFlags.Namespace) - : getSymbol(namespace.exports, qn[i], SymbolFlags.Namespace); - - if (!namespace) { - return undefined; - } - } - } - - let container = qn.length > 2 - ? getSymbol(namespace.exports, qn[qn.length - 2], SymbolFlags.Enum) - : resolveName(location, qn[qn.length - 2], SymbolFlags.Enum); - - if (!container) { - return undefined; - } - - let member = getSymbol(container.exports, qn[qn.length - 1], SymbolFlags.EnumMember); - if (!member) { - return undefined; - } - - return checker.getConstantValue(member.declarations[0]); - } - - function isWhiteSpace(ch: string) { - return whitespacePattern.test(ch); - } - - function isQuote(ch: string) { - return quotePattern.test(ch); - } - function getFactoryHiddenStateForSymbol(symbol: Symbol): FactoryHiddenState { let annotation: FactoryHiddenAnnotation; if (annotation = findAnnotation(symbol, annotation => isFactoryHiddenAnnotation(annotation) && annotation.propertyName === undefined)) { @@ -776,16 +517,13 @@ function discover() { return propertyNames; } - function getKindsForSymbol(symbol: Symbol): SyntaxKind[] { - let annotations = matchAnnotations(symbol, isKindAnnotation); - return annotations.length > 0 - ? map(annotations, annotation => annotation.kind) - : emptyArray; + function getKindsForSymbol(symbol: Symbol): KindAnnotation[] { + return matchAnnotations(symbol, isKindAnnotation); } } -function generate(outputFile: string) { - writer = createLineWrappingTextWriter(host.getNewLine(), columnWrap); +function generateFactory(outputFile: string) { + let writer = createLineWrappingTextWriter(host.getNewLine(), columnWrap); writer.write(`// `); writer.writeLine(); writer.write(`/// `); @@ -820,26 +558,46 @@ function generate(outputFile: string) { for (let syntaxNode of syntax) { writeIsNodeFunction(syntaxNode); } + + for (let typeName in memberTypeUsages) { + if (getProperty(memberTypeUsages, typeName) && !hasProperty(memberTypeUsageRedirects, typeName)) { + writeIsAnyNodeFunction(typeName); + } + } } function writeCreateFunction(syntaxNode: SyntaxNode) { + if (!syntaxNode.options.create) { + return; + } + writer.write(`export function create${syntaxNode.kindName}(`); + let first = true; for (let member of syntaxNode.members) { + if (!first) { + writer.write(`, `); + + + } + else { + first = false; + } + let type = member.isNodeArray ? `Array<${member.elementTypeName}>` : member.isModifiersArray ? `Array` : member.typeName; - writer.write(`${member.paramName}?: ${type}, `); + writer.write(`${member.paramName}?: ${type}`); } - writer.write(`location?: TextRange): ${syntaxNode.typeName} {`); + writer.write(`): ${syntaxNode.typeName} {`); writer.writeLine(); - + writer.increaseIndent(); if (syntaxNode.members.length) { - writer.write(`let node = createNode<${syntaxNode.typeName}>(SyntaxKind.${syntaxNode.kindName}, location);`); + writer.write(`let node = createNode<${syntaxNode.typeName}>(SyntaxKind.${syntaxNode.kindName});`); writer.writeLine(); if (syntaxNode.members.length > 1) { writer.write(`if (arguments.length) {`); @@ -871,7 +629,7 @@ function generate(outputFile: string) { writer.writeLine(); } else { - writer.write(`return createNode<${syntaxNode.typeName}>(SyntaxKind.${syntaxNode.kindName}, location);`); + writer.write(`return createNode<${syntaxNode.typeName}>(SyntaxKind.${syntaxNode.kindName});`); writer.writeLine(); } @@ -881,6 +639,10 @@ function generate(outputFile: string) { } function writeIsNodeFunction(syntaxNode: SyntaxNode) { + if (!syntaxNode.options.test) { + return; + } + writer.write(`export function is${syntaxNode.kindName}(node: Node): node is ${syntaxNode.typeName} {`); writer.writeLine(); writer.increaseIndent(); @@ -891,8 +653,81 @@ function generate(outputFile: string) { writer.writeLine(); } + function fillKindsForType(typeSymbol: Symbol, kinds: Symbol[]) { + let usages = getProperty(syntaxKindTypeUsages, typeSymbol.name); + if (usages) { + for (let usage of usages) { + if (kinds.indexOf(usage) === -1) { + kinds.push(usage); + } + } + } + else if (typeSymbol.declarations[0].kind === SyntaxKind.TypeAliasDeclaration) { + for (let superType of getSuperTypes(typeSymbol.declarations[0])) { + fillKindsForType(superType, kinds); + } + } + } + + function writeIsAnyNodeFunction(typeName: string) { + let typeNames = typeName.split(/\s*\|\s*/g); + if (typeNames.length === 1) { + let typeSymbol = resolveName(tsModuleSymbol.declarations[0], typeName, SymbolFlags.Type); + if (typeSymbol && findAnnotation(typeSymbol, annotation => annotation.name === "nofactoryanynodetest")) { + return; + } + } + + writer.write(`export function is${typeNames.join("Or")}(node: Node): node is ${typeNames.join(" | ")} {`); + writer.writeLine(); + writer.increaseIndent(); + + writer.write(`if (node) {`); + writer.writeLine(); + writer.increaseIndent(); + + writer.write(`switch (node.kind) {`); + writer.writeLine(); + writer.increaseIndent(); + + let kinds: Symbol[] = []; + for (let typeName of typeNames) { + let typeSymbol = resolveName(tsModuleSymbol.declarations[0], typeName, SymbolFlags.Type); + if (typeSymbol) { + fillKindsForType(typeSymbol, kinds); + } + } + + for (let kind of kinds) { + writer.write(`case SyntaxKind.${kind.name}:`); + writer.writeLine(); + } + + if (kinds.length > 0) { + writer.increaseIndent(); + writer.write(`return true;`); + writer.writeLine(); + writer.decreaseIndent(); + } + + writer.decreaseIndent(); + writer.write(`}`); + writer.writeLine(); + + writer.decreaseIndent(); + writer.write(`}`); + writer.writeLine(); + + writer.write(`return false; `); + writer.writeLine(); + + writer.decreaseIndent(); + writer.write(`}`); + writer.writeLine(); + } + function writeUpdateFunction(syntaxNode: SyntaxNode) { - if (!hasChildNodes(syntaxNode)) { + if (!syntaxNode.options.update || !hasChildNodes(syntaxNode)) { return; } @@ -987,6 +822,112 @@ function hasChildNodes(syntaxNode: SyntaxNode) { return false; } +function isTypeReferenceNode(node: Node): node is TypeReferenceNode { + return node ? node.kind === SyntaxKind.TypeReference : false; +} + +function isUnionTypeNode(node: Node): node is UnionTypeNode { + return node ? node.kind === SyntaxKind.UnionType : false; +} + +function isInterfaceDeclaration(node: Node): node is InterfaceDeclaration { + return node ? node.kind === SyntaxKind.InterfaceDeclaration : false; +} + +function isTypeAliasDeclaration(node: Node): node is TypeAliasDeclaration { + return node ? node.kind === SyntaxKind.TypeAliasDeclaration : false; +} + +function isExpressionWithTypeArguments(node: Node): node is ExpressionWithTypeArguments { + return node ? node.kind === SyntaxKind.ExpressionWithTypeArguments : false; +} + +function isNodeArray(typeNode: TypeNode): boolean { + return isTypeReferenceNode(typeNode) ? checker.getSymbolAtLocation(typeNode.typeName) === nodeArraySymbol : false; +} + +function isModifiersArray(typeNode: TypeNode): boolean { + return isTypeReferenceNode(typeNode) ? checker.getSymbolAtLocation(typeNode.typeName) === modifiersArraySymbol : false; +} + +function isSubtypeOf(node: TypeNode | Declaration, superTypeSymbol: Symbol): boolean { + if (isInterfaceDeclaration(node)) { + if (node.heritageClauses) { + for (let superType of node.heritageClauses[0].types) { + if (isSubtypeOf(superType, superTypeSymbol)) { + return true; + } + } + } + } + else if (isTypeAliasDeclaration(node)) { + return isSubtypeOf(node.type, superTypeSymbol); + } + else if (isUnionTypeNode(node)) { + for (let constituentType of node.types) { + if (isSubtypeOf(constituentType, superTypeSymbol)) { + return true; + } + } + } + else { + let typeSymbol = isTypeReferenceNode(node) ? checker.getSymbolAtLocation(node.typeName) + : isExpressionWithTypeArguments(node) ? checker.getSymbolAtLocation(node.expression) + : undefined; + + if (!typeSymbol) { + return false; + } + else if (typeSymbol === superTypeSymbol) { + return true; + } + + return isSubtypeOf(typeSymbol.declarations[0], superTypeSymbol); + } + + return false; +} + +function getSuperTypes(node: Declaration) { + let superTypes: Symbol[] = []; + let superTypeSymbolSet: boolean[] = []; + + if (isTypeAliasDeclaration(node)) { + fillSuperTypes(node.type); + } + else if (isInterfaceDeclaration(node) && node.heritageClauses) { + for (let superType of node.heritageClauses[0].types) { + fillSuperTypes(superType); + } + } + + return superTypes; + + function fillSuperTypes(node: TypeNode) { + if (isUnionTypeNode(node)) { + // Flatten union types + for (let constituentType of node.types) { + fillSuperTypes(constituentType); + } + } + else { + // Add type references + let symbol = isTypeReferenceNode(node) ? checker.getSymbolAtLocation(node.typeName) + : isExpressionWithTypeArguments(node) ? checker.getSymbolAtLocation(node.expression) + : undefined; + + if (symbol) { + if (superTypeSymbolSet[getSymbolId(symbol)]) { + return; + } + + superTypeSymbolSet[getSymbolId(symbol)] = true; + superTypes.push(symbol); + } + } + } +} + function isFactoryHiddenAnnotation(annotation: Annotation): annotation is FactoryHiddenAnnotation { return annotation.name === "factoryhidden"; } @@ -1003,10 +944,206 @@ function isKindAnnotation(annotation: Annotation): annotation is KindAnnotation return annotation.name === "kind"; } +function findAnnotation(symbol: Symbol, match: (annotation: Annotation) => boolean): TAnnotation { + for (let decl of symbol.declarations) { + for (let annotation of getAnnotationsForNode(decl)) { + if (match(annotation)) { + return annotation; + } + } + } + + return undefined; +} + +function matchAnnotations(symbol: Symbol, match: (annotation: Annotation) => boolean): TAnnotation[] { + let annotations: TAnnotation[]; + for (let decl of symbol.declarations) { + for (let annotation of getAnnotationsForNode(decl)) { + if (match(annotation)) { + if (!annotations) { + annotations = []; + } + + annotations.push(annotation); + } + } + } + + return annotations || emptyArray; +} + +function getAnnotations(symbol: Symbol): Annotation[] { + let annotations: Annotation[]; + for (let decl of symbol.declarations) { + let declAnnotations = getAnnotationsForNode(decl); + if (declAnnotations !== emptyArray) { + if (!annotations) { + annotations = []; + } + for (let annotation of declAnnotations) { + annotations.push(annotation); + } + } + } + return annotations; +} + +function getAnnotationsForNode(node: Node): Annotation[] { + let annotations = nodeAnnotations[getNodeId(node)]; + if (annotations) { + return annotations; + } + + let leadingCommentRanges = getLeadingCommentRanges(sourceFile.text, node.pos); + if (leadingCommentRanges) { + for (let range of leadingCommentRanges) { + parseAnnotations(range); + } + } + + if (!annotations) { + annotations = emptyArray; + } + + nodeAnnotations[getNodeId(node)] = annotations; + return annotations; + + function getLiteralValue(expr: Expression): any { + switch (expr.kind) { + case SyntaxKind.TrueKeyword: return true; + case SyntaxKind.FalseKeyword: return false; + case SyntaxKind.NullKeyword: return null; + case SyntaxKind.VoidExpression: return undefined; + case SyntaxKind.StringLiteral: return (expr).text; + case SyntaxKind.NoSubstitutionTemplateLiteral: return (expr).text; + case SyntaxKind.NumericLiteral: return Number((expr).text); + case SyntaxKind.PropertyAccessExpression: + return getEnumValue(node, expr.getText()); + case SyntaxKind.ArrayLiteralExpression: + return (expr).elements.map(getLiteralValue); + case SyntaxKind.ObjectLiteralExpression: + let obj: Map = {}; + for (let element of (expr).properties) { + if (element.kind !== SyntaxKind.PropertyAssignment + || (element).name.kind !== SyntaxKind.Identifier) { + continue; + } + + obj[((element).name).text] = + getLiteralValue((element).initializer); + } + return obj; + } + } + + function parseAnnotation(annotationSource: string) { + let evalSourceFile = createSourceFile("eval.ts", annotationSource, options.target, true); + let statements = evalSourceFile.statements; + if (statements.length === 0) { + return undefined; + } + + let stmt = statements[0]; + if (stmt.kind !== SyntaxKind.ExpressionStatement) { + return undefined; + } + + let expr = (stmt).expression; + if (expr.kind === SyntaxKind.Identifier) { + return createAnnotation((expr).text, emptyArray); + } + else if (expr.kind === SyntaxKind.CallExpression) { + let call = expr; + if (call.expression.kind !== SyntaxKind.Identifier) { + return undefined; + } + + let _arguments: any[] = []; + for (let argument of call.arguments) { + _arguments.push(getLiteralValue(argument)); + } + + return createAnnotation((call.expression).text, _arguments); + } + else { + return undefined; + } + } + + function parseAnnotations(range: CommentRange) { + let text = sourceFile.text; + let comment = text.substring(range.pos, range.end); + let annotationMatch: RegExpExecArray; + while (annotationMatch = annotationPattern.exec(comment)) { + let annotation = parseAnnotation(annotationMatch[1]); + if (annotation) { + if (!annotations) { + annotations = []; + } + + annotations.push(annotation); + } + } + } +} + +function getEnumValue(location: Node, name: string) { + let qn = name.split("."); + if (qn.length === 1) { + return undefined; + } + + let namespace: Symbol; + if (qn.length > 2) { + for (let i = 0; i < qn.length - 2; i++) { + namespace = i === 0 + ? resolveName(location, qn[i], SymbolFlags.Namespace) + : getSymbol(namespace.exports, qn[i], SymbolFlags.Namespace); + + if (!namespace) { + return undefined; + } + } + } + + let container = qn.length > 2 + ? getSymbol(namespace.exports, qn[qn.length - 2], SymbolFlags.Enum) + : resolveName(location, qn[qn.length - 2], SymbolFlags.Enum); + + if (!container) { + return undefined; + } + + let member = getSymbol(container.exports, qn[qn.length - 1], SymbolFlags.EnumMember); + if (!member) { + return undefined; + } + + return checker.getConstantValue(member.declarations[0]); +} + +function isWhiteSpace(ch: string) { + return whitespacePattern.test(ch); +} + +function isQuote(ch: string) { + return quotePattern.test(ch); +} + function createAnnotation(name: string, _arguments: any[]): Annotation { switch (name) { case "kind": - return { name, arguments: _arguments, kind: _arguments[0] }; + let options: KindOptions = { create: true, update: true, test: true }; + for (var p in _arguments[1]) { + (options)[p] = _arguments[1][p]; + } + return { + name, + arguments: _arguments, + kind: _arguments[0], + options + }; case "factoryhidden": if (_arguments.length >= 2 && typeof _arguments[0] === "string" && typeof _arguments[1] === "boolean") { @@ -1064,4 +1201,26 @@ function createLineWrappingTextWriter(newLine: string, maxWidth: number): EmitTe baseWrite(text); } } +} + +function getSymbol(symbols: SymbolTable, name: string, meaning: SymbolFlags) { + if (symbols && meaning && hasProperty(symbols, name)) { + let symbol = symbols[name]; + if (symbol.flags & meaning) { + return symbol; + } + } + + return undefined; +} + +function resolveName(location: Node, name: string, meaning: SymbolFlags) { + let symbols = checker.getSymbolsInScope(location, meaning); + for (let symbol of symbols) { + if (symbol.name === name) { + return symbol; + } + } + + return undefined; } \ No newline at end of file diff --git a/src/compiler/factory.generated.ts b/src/compiler/factory.generated.ts index ec5894d9322..980b8a0c395 100644 --- a/src/compiler/factory.generated.ts +++ b/src/compiler/factory.generated.ts @@ -3,51 +3,51 @@ /// namespace ts { export namespace factory { - export function createNumericLiteral(text?: string, location?: TextRange): LiteralExpression { - let node = createNode(SyntaxKind.NumericLiteral, location); + export function createNumericLiteral(text?: string): LiteralExpression { + let node = createNode(SyntaxKind.NumericLiteral); node.text = text; return node; } - export function createStringLiteral(text?: string, location?: TextRange): StringLiteral { - let node = createNode(SyntaxKind.StringLiteral, location); + export function createStringLiteral(text?: string): StringLiteral { + let node = createNode(SyntaxKind.StringLiteral); node.text = text; return node; } - export function createRegularExpressionLiteral(text?: string, location?: TextRange): LiteralExpression { - let node = createNode(SyntaxKind.RegularExpressionLiteral, location); + export function createRegularExpressionLiteral(text?: string): LiteralExpression { + let node = createNode(SyntaxKind.RegularExpressionLiteral); node.text = text; return node; } - export function createNoSubstitutionTemplateLiteral(text?: string, location?: TextRange): LiteralExpression { - let node = createNode(SyntaxKind.NoSubstitutionTemplateLiteral, location); + export function createNoSubstitutionTemplateLiteral(text?: string): LiteralExpression { + let node = createNode(SyntaxKind.NoSubstitutionTemplateLiteral); node.text = text; return node; } - export function createTemplateHead(text?: string, location?: TextRange): LiteralExpression { - let node = createNode(SyntaxKind.TemplateHead, location); + export function createTemplateHead(text?: string): LiteralExpression { + let node = createNode(SyntaxKind.TemplateHead); node.text = text; return node; } - export function createTemplateMiddle(text?: string, location?: TextRange): LiteralExpression { - let node = createNode(SyntaxKind.TemplateMiddle, location); + export function createTemplateMiddle(text?: string): LiteralExpression { + let node = createNode(SyntaxKind.TemplateMiddle); node.text = text; return node; } - export function createTemplateTail(text?: string, location?: TextRange): LiteralExpression { - let node = createNode(SyntaxKind.TemplateTail, location); + export function createTemplateTail(text?: string): LiteralExpression { + let node = createNode(SyntaxKind.TemplateTail); node.text = text; return node; } - export function createIdentifier(text?: string, originalKeywordKind?: SyntaxKind, location?: TextRange): Identifier { - let node = createNode(SyntaxKind.Identifier, location); + export function createIdentifier(text?: string, originalKeywordKind?: SyntaxKind): Identifier { + let node = createNode(SyntaxKind.Identifier); if (arguments.length) { node.text = text; node.originalKeywordKind = originalKeywordKind; } return node; } - export function createQualifiedName(left?: EntityName, right?: Identifier, location?: TextRange): QualifiedName { - let node = createNode(SyntaxKind.QualifiedName, location); + export function createQualifiedName(left?: EntityName, right?: Identifier): QualifiedName { + let node = createNode(SyntaxKind.QualifiedName); if (arguments.length) { node.left = left; node.right = right; @@ -61,8 +61,8 @@ namespace ts { } return node; } - export function createComputedPropertyName(expression?: Expression, location?: TextRange): ComputedPropertyName { - let node = createNode(SyntaxKind.ComputedPropertyName, location); + export function createComputedPropertyName(expression?: Expression): ComputedPropertyName { + let node = createNode(SyntaxKind.ComputedPropertyName); node.expression = expression; return node; } @@ -73,9 +73,8 @@ namespace ts { } return node; } - export function createTypeParameter(name?: Identifier, constraint?: TypeNode, expression?: Expression, - location?: TextRange): TypeParameterDeclaration { - let node = createNode(SyntaxKind.TypeParameter, location); + export function createTypeParameter(name?: Identifier, constraint?: TypeNode, expression?: Expression): TypeParameterDeclaration { + let node = createNode(SyntaxKind.TypeParameter); if (arguments.length) { node.name = name; node.constraint = constraint; @@ -92,9 +91,8 @@ namespace ts { return node; } export function createParameter(decorators?: Array, modifiers?: Array, dotDotDotToken?: Node, - name?: Identifier | BindingPattern, questionToken?: Node, type?: TypeNode, initializer?: Expression, - location?: TextRange): ParameterDeclaration { - let node = createNode(SyntaxKind.Parameter, location); + name?: BindingPattern | Identifier, questionToken?: Node, type?: TypeNode, initializer?: Expression): ParameterDeclaration { + let node = createNode(SyntaxKind.Parameter); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -107,7 +105,7 @@ namespace ts { return node; } export function updateParameter(node: ParameterDeclaration, decorators: Array, modifiers: Array - , name: Identifier | BindingPattern, type: TypeNode, initializer: Expression): ParameterDeclaration { + , name: BindingPattern | Identifier, type: TypeNode, initializer: Expression): ParameterDeclaration { if (decorators !== node.decorators || modifiers !== node.modifiers || name !== node.name || type !== node.type || initializer !== node.initializer) { let newNode = createParameter(decorators, modifiers, node.dotDotDotToken, name, node.questionToken, type, initializer); @@ -115,8 +113,8 @@ namespace ts { } return node; } - export function createDecorator(expression?: LeftHandSideExpression, location?: TextRange): Decorator { - let node = createNode(SyntaxKind.Decorator, location); + export function createDecorator(expression?: LeftHandSideExpression): Decorator { + let node = createNode(SyntaxKind.Decorator); node.expression = expression; return node; } @@ -128,8 +126,8 @@ namespace ts { return node; } export function createPropertySignature(decorators?: Array, modifiers?: Array, name?: DeclarationName, questionToken?: Node, - type?: TypeNode, location?: TextRange): PropertySignature { - let node = createNode(SyntaxKind.PropertySignature, location); + type?: TypeNode): PropertySignature { + let node = createNode(SyntaxKind.PropertySignature); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -148,8 +146,8 @@ namespace ts { return node; } export function createPropertyDeclaration(decorators?: Array, modifiers?: Array, name?: DeclarationName, - questionToken?: Node, type?: TypeNode, initializer?: Expression, location?: TextRange): PropertyDeclaration { - let node = createNode(SyntaxKind.PropertyDeclaration, location); + questionToken?: Node, type?: TypeNode, initializer?: Expression): PropertyDeclaration { + let node = createNode(SyntaxKind.PropertyDeclaration); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -170,9 +168,8 @@ namespace ts { return node; } export function createMethodSignature(decorators?: Array, modifiers?: Array, name?: DeclarationName, questionToken?: Node, - typeParameters?: Array, parameters?: Array, type?: TypeNode, - location?: TextRange): MethodSignature { - let node = createNode(SyntaxKind.MethodSignature, location); + typeParameters?: Array, parameters?: Array, type?: TypeNode): MethodSignature { + let node = createNode(SyntaxKind.MethodSignature); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -194,9 +191,9 @@ namespace ts { return node; } export function createMethodDeclaration(decorators?: Array, modifiers?: Array, name?: DeclarationName, - typeParameters?: Array, parameters?: Array, type?: TypeNode, body?: Block, - location?: TextRange): MethodDeclaration { - let node = createNode(SyntaxKind.MethodDeclaration, location); + typeParameters?: Array, parameters?: Array, type?: TypeNode, body?: Block + ): MethodDeclaration { + let node = createNode(SyntaxKind.MethodDeclaration); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -219,8 +216,8 @@ namespace ts { return node; } export function createConstructor(decorators?: Array, modifiers?: Array, parameters?: Array, - type?: TypeNode, body?: Block, location?: TextRange): ConstructorDeclaration { - let node = createNode(SyntaxKind.Constructor, location); + type?: TypeNode, body?: Block): ConstructorDeclaration { + let node = createNode(SyntaxKind.Constructor); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -240,8 +237,8 @@ namespace ts { return node; } export function createGetAccessor(decorators?: Array, modifiers?: Array, name?: DeclarationName, - parameters?: Array, type?: TypeNode, body?: Block, location?: TextRange): GetAccessorDeclaration { - let node = createNode(SyntaxKind.GetAccessor, location); + parameters?: Array, type?: TypeNode, body?: Block): GetAccessorDeclaration { + let node = createNode(SyntaxKind.GetAccessor); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -262,8 +259,8 @@ namespace ts { return node; } export function createSetAccessor(decorators?: Array, modifiers?: Array, name?: DeclarationName, - parameters?: Array, type?: TypeNode, body?: Block, location?: TextRange): SetAccessorDeclaration { - let node = createNode(SyntaxKind.SetAccessor, location); + parameters?: Array, type?: TypeNode, body?: Block): SetAccessorDeclaration { + let node = createNode(SyntaxKind.SetAccessor); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -284,8 +281,8 @@ namespace ts { return node; } export function createCallSignature(typeParameters?: Array, parameters?: Array, - type?: TypeNode, location?: TextRange): CallSignatureDeclaration { - let node = createNode(SyntaxKind.CallSignature, location); + type?: TypeNode): CallSignatureDeclaration { + let node = createNode(SyntaxKind.CallSignature); if (arguments.length) { node.typeParameters = typeParameters && createNodeArray(typeParameters) node.parameters = parameters && createNodeArray(parameters) @@ -302,8 +299,8 @@ namespace ts { return node; } export function createConstructSignature(typeParameters?: Array, parameters?: Array, - type?: TypeNode, location?: TextRange): ConstructSignatureDeclaration { - let node = createNode(SyntaxKind.ConstructSignature, location); + type?: TypeNode): ConstructSignatureDeclaration { + let node = createNode(SyntaxKind.ConstructSignature); if (arguments.length) { node.typeParameters = typeParameters && createNodeArray(typeParameters) node.parameters = parameters && createNodeArray(parameters) @@ -320,8 +317,8 @@ namespace ts { return node; } export function createIndexSignature(decorators?: Array, modifiers?: Array, parameters?: Array, - type?: TypeNode, location?: TextRange): IndexSignatureDeclaration { - let node = createNode(SyntaxKind.IndexSignature, location); + type?: TypeNode): IndexSignatureDeclaration { + let node = createNode(SyntaxKind.IndexSignature); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -338,8 +335,8 @@ namespace ts { } return node; } - export function createTypePredicate(parameterName?: Identifier, type?: TypeNode, location?: TextRange): TypePredicateNode { - let node = createNode(SyntaxKind.TypePredicate, location); + export function createTypePredicate(parameterName?: Identifier, type?: TypeNode): TypePredicateNode { + let node = createNode(SyntaxKind.TypePredicate); if (arguments.length) { node.parameterName = parameterName; node.type = type; @@ -353,8 +350,8 @@ namespace ts { } return node; } - export function createTypeReference(typeName?: EntityName, typeArguments?: Array, location?: TextRange): TypeReferenceNode { - let node = createNode(SyntaxKind.TypeReference, location); + export function createTypeReference(typeName?: EntityName, typeArguments?: Array): TypeReferenceNode { + let node = createNode(SyntaxKind.TypeReference); if (arguments.length) { node.typeName = typeName; node.typeArguments = typeArguments && createNodeArray(typeArguments) @@ -369,8 +366,8 @@ namespace ts { return node; } export function createFunctionType(typeParameters?: Array, parameters?: Array, - type?: TypeNode, location?: TextRange): FunctionTypeNode { - let node = createNode(SyntaxKind.FunctionType, location); + type?: TypeNode): FunctionTypeNode { + let node = createNode(SyntaxKind.FunctionType); if (arguments.length) { node.typeParameters = typeParameters && createNodeArray(typeParameters) node.parameters = parameters && createNodeArray(parameters) @@ -387,8 +384,8 @@ namespace ts { return node; } export function createConstructorType(typeParameters?: Array, parameters?: Array, - type?: TypeNode, location?: TextRange): ConstructorTypeNode { - let node = createNode(SyntaxKind.ConstructorType, location); + type?: TypeNode): ConstructorTypeNode { + let node = createNode(SyntaxKind.ConstructorType); if (arguments.length) { node.typeParameters = typeParameters && createNodeArray(typeParameters) node.parameters = parameters && createNodeArray(parameters) @@ -404,8 +401,8 @@ namespace ts { } return node; } - export function createTypeQuery(exprName?: EntityName, location?: TextRange): TypeQueryNode { - let node = createNode(SyntaxKind.TypeQuery, location); + export function createTypeQuery(exprName?: EntityName): TypeQueryNode { + let node = createNode(SyntaxKind.TypeQuery); node.exprName = exprName; return node; } @@ -416,8 +413,8 @@ namespace ts { } return node; } - export function createTypeLiteral(members?: Array, location?: TextRange): TypeLiteralNode { - let node = createNode(SyntaxKind.TypeLiteral, location); + export function createTypeLiteral(members?: Array): TypeLiteralNode { + let node = createNode(SyntaxKind.TypeLiteral); node.members = members && createNodeArray(members) return node; } @@ -428,8 +425,8 @@ namespace ts { } return node; } - export function createArrayType(elementType?: TypeNode, location?: TextRange): ArrayTypeNode { - let node = createNode(SyntaxKind.ArrayType, location); + export function createArrayType(elementType?: TypeNode): ArrayTypeNode { + let node = createNode(SyntaxKind.ArrayType); node.elementType = elementType; return node; } @@ -440,8 +437,8 @@ namespace ts { } return node; } - export function createTupleType(elementTypes?: Array, location?: TextRange): TupleTypeNode { - let node = createNode(SyntaxKind.TupleType, location); + export function createTupleType(elementTypes?: Array): TupleTypeNode { + let node = createNode(SyntaxKind.TupleType); node.elementTypes = elementTypes && createNodeArray(elementTypes) return node; } @@ -452,8 +449,8 @@ namespace ts { } return node; } - export function createUnionType(types?: Array, location?: TextRange): UnionTypeNode { - let node = createNode(SyntaxKind.UnionType, location); + export function createUnionType(types?: Array): UnionTypeNode { + let node = createNode(SyntaxKind.UnionType); node.types = types && createNodeArray(types) return node; } @@ -464,8 +461,8 @@ namespace ts { } return node; } - export function createIntersectionType(types?: Array, location?: TextRange): IntersectionTypeNode { - let node = createNode(SyntaxKind.IntersectionType, location); + export function createIntersectionType(types?: Array): IntersectionTypeNode { + let node = createNode(SyntaxKind.IntersectionType); node.types = types && createNodeArray(types) return node; } @@ -476,8 +473,8 @@ namespace ts { } return node; } - export function createParenthesizedType(type?: TypeNode, location?: TextRange): ParenthesizedTypeNode { - let node = createNode(SyntaxKind.ParenthesizedType, location); + export function createParenthesizedType(type?: TypeNode): ParenthesizedTypeNode { + let node = createNode(SyntaxKind.ParenthesizedType); node.type = type; return node; } @@ -488,8 +485,8 @@ namespace ts { } return node; } - export function createObjectBindingPattern(elements?: Array, location?: TextRange): ObjectBindingPattern { - let node = createNode(SyntaxKind.ObjectBindingPattern, location); + export function createObjectBindingPattern(elements?: Array): ObjectBindingPattern { + let node = createNode(SyntaxKind.ObjectBindingPattern); node.elements = elements && createNodeArray(elements) return node; } @@ -500,8 +497,8 @@ namespace ts { } return node; } - export function createArrayBindingPattern(elements?: Array, location?: TextRange): ArrayBindingPattern { - let node = createNode(SyntaxKind.ArrayBindingPattern, location); + export function createArrayBindingPattern(elements?: Array): ArrayBindingPattern { + let node = createNode(SyntaxKind.ArrayBindingPattern); node.elements = elements && createNodeArray(elements) return node; } @@ -512,9 +509,9 @@ namespace ts { } return node; } - export function createBindingElement(decorators?: Array, modifiers?: Array, propertyName?: Identifier, - dotDotDotToken?: Node, name?: Identifier | BindingPattern, initializer?: Expression, location?: TextRange): BindingElement { - let node = createNode(SyntaxKind.BindingElement, location); + export function createBindingElement(decorators?: Array, modifiers?: Array, propertyName?: Identifier, dotDotDotToken?: Node + , name?: BindingPattern | Identifier, initializer?: Expression): BindingElement { + let node = createNode(SyntaxKind.BindingElement); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -526,7 +523,7 @@ namespace ts { return node; } export function updateBindingElement(node: BindingElement, decorators: Array, modifiers: Array, propertyName: Identifier - , name: Identifier | BindingPattern, initializer: Expression): BindingElement { + , name: BindingPattern | Identifier, initializer: Expression): BindingElement { if (decorators !== node.decorators || modifiers !== node.modifiers || propertyName !== node.propertyName || name !== node.name || initializer !== node.initializer) { let newNode = createBindingElement(decorators, modifiers, propertyName, node.dotDotDotToken, name, initializer); @@ -534,8 +531,8 @@ namespace ts { } return node; } - export function createArrayLiteralExpression(elements?: Array, location?: TextRange): ArrayLiteralExpression { - let node = createNode(SyntaxKind.ArrayLiteralExpression, location); + export function createArrayLiteralExpression(elements?: Array): ArrayLiteralExpression { + let node = createNode(SyntaxKind.ArrayLiteralExpression); node.elements = elements && createNodeArray(elements) return node; } @@ -547,8 +544,8 @@ namespace ts { return node; } export function createObjectLiteralExpression(decorators?: Array, modifiers?: Array, - properties?: Array, location?: TextRange): ObjectLiteralExpression { - let node = createNode(SyntaxKind.ObjectLiteralExpression, location); + properties?: Array): ObjectLiteralExpression { + let node = createNode(SyntaxKind.ObjectLiteralExpression); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -564,9 +561,9 @@ namespace ts { } return node; } - export function createPropertyAccessExpression(expression?: LeftHandSideExpression, dotToken?: Node, name?: Identifier, - location?: TextRange): PropertyAccessExpression { - let node = createNode(SyntaxKind.PropertyAccessExpression, location); + export function createPropertyAccessExpression(expression?: LeftHandSideExpression, dotToken?: Node, name?: Identifier + ): PropertyAccessExpression { + let node = createNode(SyntaxKind.PropertyAccessExpression); if (arguments.length) { node.expression = expression; node.dotToken = dotToken; @@ -582,9 +579,9 @@ namespace ts { } return node; } - export function createElementAccessExpression(expression?: LeftHandSideExpression, argumentExpression?: Expression, - location?: TextRange): ElementAccessExpression { - let node = createNode(SyntaxKind.ElementAccessExpression, location); + export function createElementAccessExpression(expression?: LeftHandSideExpression, argumentExpression?: Expression + ): ElementAccessExpression { + let node = createNode(SyntaxKind.ElementAccessExpression); if (arguments.length) { node.expression = expression; node.argumentExpression = argumentExpression; @@ -599,9 +596,9 @@ namespace ts { } return node; } - export function createCallExpression(expression?: LeftHandSideExpression, typeArguments?: Array, _arguments?: Array, - location?: TextRange): CallExpression { - let node = createNode(SyntaxKind.CallExpression, location); + export function createCallExpression(expression?: LeftHandSideExpression, typeArguments?: Array, _arguments?: Array + ): CallExpression { + let node = createNode(SyntaxKind.CallExpression); if (arguments.length) { node.expression = expression; node.typeArguments = typeArguments && createNodeArray(typeArguments) @@ -617,9 +614,9 @@ namespace ts { } return node; } - export function createNewExpression(expression?: LeftHandSideExpression, typeArguments?: Array, _arguments?: Array, - location?: TextRange): NewExpression { - let node = createNode(SyntaxKind.NewExpression, location); + export function createNewExpression(expression?: LeftHandSideExpression, typeArguments?: Array, _arguments?: Array + ): NewExpression { + let node = createNode(SyntaxKind.NewExpression); if (arguments.length) { node.expression = expression; node.typeArguments = typeArguments && createNodeArray(typeArguments) @@ -635,9 +632,9 @@ namespace ts { } return node; } - export function createTaggedTemplateExpression(tag?: LeftHandSideExpression, template?: LiteralExpression | TemplateExpression, - location?: TextRange): TaggedTemplateExpression { - let node = createNode(SyntaxKind.TaggedTemplateExpression, location); + export function createTaggedTemplateExpression(tag?: LeftHandSideExpression, template?: LiteralExpression | TemplateExpression + ): TaggedTemplateExpression { + let node = createNode(SyntaxKind.TaggedTemplateExpression); if (arguments.length) { node.tag = tag; node.template = template; @@ -652,8 +649,8 @@ namespace ts { } return node; } - export function createTypeAssertionExpression(type?: TypeNode, expression?: UnaryExpression, location?: TextRange): TypeAssertion { - let node = createNode(SyntaxKind.TypeAssertionExpression, location); + export function createTypeAssertionExpression(type?: TypeNode, expression?: UnaryExpression): TypeAssertion { + let node = createNode(SyntaxKind.TypeAssertionExpression); if (arguments.length) { node.type = type; node.expression = expression; @@ -667,8 +664,8 @@ namespace ts { } return node; } - export function createParenthesizedExpression(expression?: Expression, location?: TextRange): ParenthesizedExpression { - let node = createNode(SyntaxKind.ParenthesizedExpression, location); + export function createParenthesizedExpression(expression?: Expression): ParenthesizedExpression { + let node = createNode(SyntaxKind.ParenthesizedExpression); node.expression = expression; return node; } @@ -680,9 +677,9 @@ namespace ts { return node; } export function createFunctionExpression(decorators?: Array, modifiers?: Array, asteriskToken?: Node, name?: Identifier, - typeParameters?: Array, parameters?: Array, type?: TypeNode, body?: Block | Expression, - location?: TextRange): FunctionExpression { - let node = createNode(SyntaxKind.FunctionExpression, location); + typeParameters?: Array, parameters?: Array, type?: TypeNode, body?: Block | Expression + ): FunctionExpression { + let node = createNode(SyntaxKind.FunctionExpression); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -706,9 +703,8 @@ namespace ts { return node; } export function createArrowFunction(decorators?: Array, modifiers?: Array, typeParameters?: Array, - parameters?: Array, type?: TypeNode, equalsGreaterThanToken?: Node, body?: Block | Expression, - location?: TextRange): ArrowFunction { - let node = createNode(SyntaxKind.ArrowFunction, location); + parameters?: Array, type?: TypeNode, equalsGreaterThanToken?: Node, body?: Block | Expression): ArrowFunction { + let node = createNode(SyntaxKind.ArrowFunction); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -730,8 +726,8 @@ namespace ts { } return node; } - export function createDeleteExpression(expression?: UnaryExpression, location?: TextRange): DeleteExpression { - let node = createNode(SyntaxKind.DeleteExpression, location); + export function createDeleteExpression(expression?: UnaryExpression): DeleteExpression { + let node = createNode(SyntaxKind.DeleteExpression); node.expression = expression; return node; } @@ -742,8 +738,8 @@ namespace ts { } return node; } - export function createTypeOfExpression(expression?: UnaryExpression, location?: TextRange): TypeOfExpression { - let node = createNode(SyntaxKind.TypeOfExpression, location); + export function createTypeOfExpression(expression?: UnaryExpression): TypeOfExpression { + let node = createNode(SyntaxKind.TypeOfExpression); node.expression = expression; return node; } @@ -754,8 +750,8 @@ namespace ts { } return node; } - export function createVoidExpression(expression?: UnaryExpression, location?: TextRange): VoidExpression { - let node = createNode(SyntaxKind.VoidExpression, location); + export function createVoidExpression(expression?: UnaryExpression): VoidExpression { + let node = createNode(SyntaxKind.VoidExpression); node.expression = expression; return node; } @@ -766,8 +762,8 @@ namespace ts { } return node; } - export function createAwaitExpression(expression?: UnaryExpression, location?: TextRange): AwaitExpression { - let node = createNode(SyntaxKind.AwaitExpression, location); + export function createAwaitExpression(expression?: UnaryExpression): AwaitExpression { + let node = createNode(SyntaxKind.AwaitExpression); node.expression = expression; return node; } @@ -778,8 +774,8 @@ namespace ts { } return node; } - export function createPrefixUnaryExpression(operator?: SyntaxKind, operand?: UnaryExpression, location?: TextRange): PrefixUnaryExpression { - let node = createNode(SyntaxKind.PrefixUnaryExpression, location); + export function createPrefixUnaryExpression(operator?: SyntaxKind, operand?: UnaryExpression): PrefixUnaryExpression { + let node = createNode(SyntaxKind.PrefixUnaryExpression); if (arguments.length) { node.operator = operator; node.operand = operand; @@ -793,9 +789,8 @@ namespace ts { } return node; } - export function createPostfixUnaryExpression(operand?: LeftHandSideExpression, operator?: SyntaxKind, - location?: TextRange): PostfixUnaryExpression { - let node = createNode(SyntaxKind.PostfixUnaryExpression, location); + export function createPostfixUnaryExpression(operand?: LeftHandSideExpression, operator?: SyntaxKind): PostfixUnaryExpression { + let node = createNode(SyntaxKind.PostfixUnaryExpression); if (arguments.length) { node.operand = operand; node.operator = operator; @@ -809,8 +804,8 @@ namespace ts { } return node; } - export function createBinaryExpression(left?: Expression, operatorToken?: Node, right?: Expression, location?: TextRange): BinaryExpression { - let node = createNode(SyntaxKind.BinaryExpression, location); + export function createBinaryExpression(left?: Expression, operatorToken?: Node, right?: Expression): BinaryExpression { + let node = createNode(SyntaxKind.BinaryExpression); if (arguments.length) { node.left = left; node.operatorToken = operatorToken; @@ -826,8 +821,8 @@ namespace ts { return node; } export function createConditionalExpression(condition?: Expression, questionToken?: Node, whenTrue?: Expression, colonToken?: Node, - whenFalse?: Expression, location?: TextRange): ConditionalExpression { - let node = createNode(SyntaxKind.ConditionalExpression, location); + whenFalse?: Expression): ConditionalExpression { + let node = createNode(SyntaxKind.ConditionalExpression); if (arguments.length) { node.condition = condition; node.questionToken = questionToken; @@ -845,9 +840,8 @@ namespace ts { } return node; } - export function createTemplateExpression(head?: LiteralExpression, templateSpans?: Array, - location?: TextRange): TemplateExpression { - let node = createNode(SyntaxKind.TemplateExpression, location); + export function createTemplateExpression(head?: LiteralExpression, templateSpans?: Array): TemplateExpression { + let node = createNode(SyntaxKind.TemplateExpression); if (arguments.length) { node.head = head; node.templateSpans = templateSpans && createNodeArray(templateSpans) @@ -862,8 +856,8 @@ namespace ts { } return node; } - export function createYieldExpression(asteriskToken?: Node, expression?: Expression, location?: TextRange): YieldExpression { - let node = createNode(SyntaxKind.YieldExpression, location); + export function createYieldExpression(asteriskToken?: Node, expression?: Expression): YieldExpression { + let node = createNode(SyntaxKind.YieldExpression); if (arguments.length) { node.asteriskToken = asteriskToken; node.expression = expression; @@ -877,8 +871,8 @@ namespace ts { } return node; } - export function createSpreadElementExpression(expression?: Expression, location?: TextRange): SpreadElementExpression { - let node = createNode(SyntaxKind.SpreadElementExpression, location); + export function createSpreadElementExpression(expression?: Expression): SpreadElementExpression { + let node = createNode(SyntaxKind.SpreadElementExpression); node.expression = expression; return node; } @@ -890,9 +884,9 @@ namespace ts { return node; } export function createClassExpression(decorators?: Array, modifiers?: Array, name?: Identifier, - typeParameters?: Array, heritageClauses?: Array, members?: Array, - location?: TextRange): ClassExpression { - let node = createNode(SyntaxKind.ClassExpression, location); + typeParameters?: Array, heritageClauses?: Array, members?: Array + ): ClassExpression { + let node = createNode(SyntaxKind.ClassExpression); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -913,12 +907,12 @@ namespace ts { } return node; } - export function createOmittedExpression(location?: TextRange): Expression { - return createNode(SyntaxKind.OmittedExpression, location); + export function createOmittedExpression(): Expression { + return createNode(SyntaxKind.OmittedExpression); } - export function createExpressionWithTypeArguments(expression?: LeftHandSideExpression, typeArguments?: Array, - location?: TextRange): ExpressionWithTypeArguments { - let node = createNode(SyntaxKind.ExpressionWithTypeArguments, location); + export function createExpressionWithTypeArguments(expression?: LeftHandSideExpression, typeArguments?: Array + ): ExpressionWithTypeArguments { + let node = createNode(SyntaxKind.ExpressionWithTypeArguments); if (arguments.length) { node.expression = expression; node.typeArguments = typeArguments && createNodeArray(typeArguments) @@ -933,8 +927,8 @@ namespace ts { } return node; } - export function createAsExpression(expression?: Expression, type?: TypeNode, location?: TextRange): AsExpression { - let node = createNode(SyntaxKind.AsExpression, location); + export function createAsExpression(expression?: Expression, type?: TypeNode): AsExpression { + let node = createNode(SyntaxKind.AsExpression); if (arguments.length) { node.expression = expression; node.type = type; @@ -948,8 +942,8 @@ namespace ts { } return node; } - export function createTemplateSpan(expression?: Expression, literal?: LiteralExpression, location?: TextRange): TemplateSpan { - let node = createNode(SyntaxKind.TemplateSpan, location); + export function createTemplateSpan(expression?: Expression, literal?: LiteralExpression): TemplateSpan { + let node = createNode(SyntaxKind.TemplateSpan); if (arguments.length) { node.expression = expression; node.literal = literal; @@ -963,11 +957,11 @@ namespace ts { } return node; } - export function createSemicolonClassElement(location?: TextRange): SemicolonClassElement { - return createNode(SyntaxKind.SemicolonClassElement, location); + export function createSemicolonClassElement(): SemicolonClassElement { + return createNode(SyntaxKind.SemicolonClassElement); } - export function createBlock(statements?: Array, location?: TextRange): Block { - let node = createNode(SyntaxKind.Block, location); + export function createBlock(statements?: Array): Block { + let node = createNode(SyntaxKind.Block); node.statements = statements && createNodeArray(statements) return node; } @@ -978,8 +972,8 @@ namespace ts { } return node; } - export function createVariableStatement(declarationList?: VariableDeclarationList, location?: TextRange): VariableStatement { - let node = createNode(SyntaxKind.VariableStatement, location); + export function createVariableStatement(declarationList?: VariableDeclarationList): VariableStatement { + let node = createNode(SyntaxKind.VariableStatement); node.declarationList = declarationList; return node; } @@ -990,11 +984,11 @@ namespace ts { } return node; } - export function createEmptyStatement(location?: TextRange): Statement { - return createNode(SyntaxKind.EmptyStatement, location); + export function createEmptyStatement(): EmptyStatement { + return createNode(SyntaxKind.EmptyStatement); } - export function createExpressionStatement(expression?: Expression, location?: TextRange): ExpressionStatement { - let node = createNode(SyntaxKind.ExpressionStatement, location); + export function createExpressionStatement(expression?: Expression): ExpressionStatement { + let node = createNode(SyntaxKind.ExpressionStatement); node.expression = expression; return node; } @@ -1005,9 +999,8 @@ namespace ts { } return node; } - export function createIfStatement(expression?: Expression, thenStatement?: Statement, elseStatement?: Statement, - location?: TextRange): IfStatement { - let node = createNode(SyntaxKind.IfStatement, location); + export function createIfStatement(expression?: Expression, thenStatement?: Statement, elseStatement?: Statement): IfStatement { + let node = createNode(SyntaxKind.IfStatement); if (arguments.length) { node.expression = expression; node.thenStatement = thenStatement; @@ -1023,8 +1016,8 @@ namespace ts { } return node; } - export function createDoStatement(statement?: Statement, expression?: Expression, location?: TextRange): DoStatement { - let node = createNode(SyntaxKind.DoStatement, location); + export function createDoStatement(statement?: Statement, expression?: Expression): DoStatement { + let node = createNode(SyntaxKind.DoStatement); if (arguments.length) { node.statement = statement; node.expression = expression; @@ -1038,8 +1031,8 @@ namespace ts { } return node; } - export function createWhileStatement(expression?: Expression, statement?: Statement, location?: TextRange): WhileStatement { - let node = createNode(SyntaxKind.WhileStatement, location); + export function createWhileStatement(expression?: Expression, statement?: Statement): WhileStatement { + let node = createNode(SyntaxKind.WhileStatement); if (arguments.length) { node.expression = expression; node.statement = statement; @@ -1053,9 +1046,9 @@ namespace ts { } return node; } - export function createForStatement(initializer?: VariableDeclarationList | Expression, condition?: Expression, incrementor?: Expression, - statement?: Statement, location?: TextRange): ForStatement { - let node = createNode(SyntaxKind.ForStatement, location); + export function createForStatement(initializer?: Expression | VariableDeclarationList, condition?: Expression, incrementor?: Expression, + statement?: Statement): ForStatement { + let node = createNode(SyntaxKind.ForStatement); if (arguments.length) { node.initializer = initializer; node.condition = condition; @@ -1064,7 +1057,7 @@ namespace ts { } return node; } - export function updateForStatement(node: ForStatement, initializer: VariableDeclarationList | Expression, condition: Expression + export function updateForStatement(node: ForStatement, initializer: Expression | VariableDeclarationList, condition: Expression , incrementor: Expression, statement: Statement): ForStatement { if (initializer !== node.initializer || condition !== node.condition || incrementor !== node.incrementor || statement !== node.statement ) { @@ -1073,9 +1066,9 @@ namespace ts { } return node; } - export function createForInStatement(initializer?: VariableDeclarationList | Expression, expression?: Expression, statement?: Statement, - location?: TextRange): ForInStatement { - let node = createNode(SyntaxKind.ForInStatement, location); + export function createForInStatement(initializer?: Expression | VariableDeclarationList, expression?: Expression, statement?: Statement + ): ForInStatement { + let node = createNode(SyntaxKind.ForInStatement); if (arguments.length) { node.initializer = initializer; node.expression = expression; @@ -1083,7 +1076,7 @@ namespace ts { } return node; } - export function updateForInStatement(node: ForInStatement, initializer: VariableDeclarationList | Expression, expression: Expression + export function updateForInStatement(node: ForInStatement, initializer: Expression | VariableDeclarationList, expression: Expression , statement: Statement): ForInStatement { if (initializer !== node.initializer || expression !== node.expression || statement !== node.statement) { let newNode = createForInStatement(initializer, expression, statement); @@ -1091,9 +1084,9 @@ namespace ts { } return node; } - export function createForOfStatement(initializer?: VariableDeclarationList | Expression, expression?: Expression, statement?: Statement, - location?: TextRange): ForOfStatement { - let node = createNode(SyntaxKind.ForOfStatement, location); + export function createForOfStatement(initializer?: Expression | VariableDeclarationList, expression?: Expression, statement?: Statement + ): ForOfStatement { + let node = createNode(SyntaxKind.ForOfStatement); if (arguments.length) { node.initializer = initializer; node.expression = expression; @@ -1101,7 +1094,7 @@ namespace ts { } return node; } - export function updateForOfStatement(node: ForOfStatement, initializer: VariableDeclarationList | Expression, expression: Expression + export function updateForOfStatement(node: ForOfStatement, initializer: Expression | VariableDeclarationList, expression: Expression , statement: Statement): ForOfStatement { if (initializer !== node.initializer || expression !== node.expression || statement !== node.statement) { let newNode = createForOfStatement(initializer, expression, statement); @@ -1109,8 +1102,8 @@ namespace ts { } return node; } - export function createContinueStatement(label?: Identifier, location?: TextRange): ContinueStatement { - let node = createNode(SyntaxKind.ContinueStatement, location); + export function createContinueStatement(label?: Identifier): ContinueStatement { + let node = createNode(SyntaxKind.ContinueStatement); node.label = label; return node; } @@ -1121,8 +1114,8 @@ namespace ts { } return node; } - export function createBreakStatement(label?: Identifier, location?: TextRange): BreakStatement { - let node = createNode(SyntaxKind.BreakStatement, location); + export function createBreakStatement(label?: Identifier): BreakStatement { + let node = createNode(SyntaxKind.BreakStatement); node.label = label; return node; } @@ -1133,8 +1126,8 @@ namespace ts { } return node; } - export function createReturnStatement(expression?: Expression, location?: TextRange): ReturnStatement { - let node = createNode(SyntaxKind.ReturnStatement, location); + export function createReturnStatement(expression?: Expression): ReturnStatement { + let node = createNode(SyntaxKind.ReturnStatement); node.expression = expression; return node; } @@ -1145,8 +1138,8 @@ namespace ts { } return node; } - export function createWithStatement(expression?: Expression, statement?: Statement, location?: TextRange): WithStatement { - let node = createNode(SyntaxKind.WithStatement, location); + export function createWithStatement(expression?: Expression, statement?: Statement): WithStatement { + let node = createNode(SyntaxKind.WithStatement); if (arguments.length) { node.expression = expression; node.statement = statement; @@ -1160,8 +1153,8 @@ namespace ts { } return node; } - export function createSwitchStatement(expression?: Expression, caseBlock?: CaseBlock, location?: TextRange): SwitchStatement { - let node = createNode(SyntaxKind.SwitchStatement, location); + export function createSwitchStatement(expression?: Expression, caseBlock?: CaseBlock): SwitchStatement { + let node = createNode(SyntaxKind.SwitchStatement); if (arguments.length) { node.expression = expression; node.caseBlock = caseBlock; @@ -1175,8 +1168,8 @@ namespace ts { } return node; } - export function createLabeledStatement(label?: Identifier, statement?: Statement, location?: TextRange): LabeledStatement { - let node = createNode(SyntaxKind.LabeledStatement, location); + export function createLabeledStatement(label?: Identifier, statement?: Statement): LabeledStatement { + let node = createNode(SyntaxKind.LabeledStatement); if (arguments.length) { node.label = label; node.statement = statement; @@ -1190,8 +1183,8 @@ namespace ts { } return node; } - export function createThrowStatement(expression?: Expression, location?: TextRange): ThrowStatement { - let node = createNode(SyntaxKind.ThrowStatement, location); + export function createThrowStatement(expression?: Expression): ThrowStatement { + let node = createNode(SyntaxKind.ThrowStatement); node.expression = expression; return node; } @@ -1202,8 +1195,8 @@ namespace ts { } return node; } - export function createTryStatement(tryBlock?: Block, catchClause?: CatchClause, finallyBlock?: Block, location?: TextRange): TryStatement { - let node = createNode(SyntaxKind.TryStatement, location); + export function createTryStatement(tryBlock?: Block, catchClause?: CatchClause, finallyBlock?: Block): TryStatement { + let node = createNode(SyntaxKind.TryStatement); if (arguments.length) { node.tryBlock = tryBlock; node.catchClause = catchClause; @@ -1218,12 +1211,12 @@ namespace ts { } return node; } - export function createDebuggerStatement(location?: TextRange): Statement { - return createNode(SyntaxKind.DebuggerStatement, location); + export function createDebuggerStatement(): DebuggerStatement { + return createNode(SyntaxKind.DebuggerStatement); } - export function createVariableDeclaration(decorators?: Array, modifiers?: Array, name?: Identifier | BindingPattern, - type?: TypeNode, initializer?: Expression, location?: TextRange): VariableDeclaration { - let node = createNode(SyntaxKind.VariableDeclaration, location); + export function createVariableDeclaration(decorators?: Array, modifiers?: Array, name?: BindingPattern | Identifier, + type?: TypeNode, initializer?: Expression): VariableDeclaration { + let node = createNode(SyntaxKind.VariableDeclaration); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -1234,7 +1227,7 @@ namespace ts { return node; } export function updateVariableDeclaration(node: VariableDeclaration, decorators: Array, modifiers: Array - , name: Identifier | BindingPattern, type: TypeNode, initializer: Expression): VariableDeclaration { + , name: BindingPattern | Identifier, type: TypeNode, initializer: Expression): VariableDeclaration { if (decorators !== node.decorators || modifiers !== node.modifiers || name !== node.name || type !== node.type || initializer !== node.initializer) { let newNode = createVariableDeclaration(decorators, modifiers, name, type, initializer); @@ -1242,8 +1235,8 @@ namespace ts { } return node; } - export function createVariableDeclarationList(declarations?: Array, location?: TextRange): VariableDeclarationList { - let node = createNode(SyntaxKind.VariableDeclarationList, location); + export function createVariableDeclarationList(declarations?: Array): VariableDeclarationList { + let node = createNode(SyntaxKind.VariableDeclarationList); node.declarations = declarations && createNodeArray(declarations) return node; } @@ -1256,9 +1249,9 @@ namespace ts { return node; } export function createFunctionDeclaration(decorators?: Array, modifiers?: Array, asteriskToken?: Node, name?: Identifier, - typeParameters?: Array, parameters?: Array, type?: TypeNode, body?: Block, - location?: TextRange): FunctionDeclaration { - let node = createNode(SyntaxKind.FunctionDeclaration, location); + typeParameters?: Array, parameters?: Array, type?: TypeNode, body?: Block + ): FunctionDeclaration { + let node = createNode(SyntaxKind.FunctionDeclaration); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -1282,9 +1275,9 @@ namespace ts { return node; } export function createClassDeclaration(decorators?: Array, modifiers?: Array, name?: Identifier, - typeParameters?: Array, heritageClauses?: Array, members?: Array, - location?: TextRange): ClassDeclaration { - let node = createNode(SyntaxKind.ClassDeclaration, location); + typeParameters?: Array, heritageClauses?: Array, members?: Array + ): ClassDeclaration { + let node = createNode(SyntaxKind.ClassDeclaration); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -1306,9 +1299,9 @@ namespace ts { return node; } export function createInterfaceDeclaration(decorators?: Array, modifiers?: Array, name?: Identifier, - typeParameters?: Array, heritageClauses?: Array, members?: Array, - location?: TextRange): InterfaceDeclaration { - let node = createNode(SyntaxKind.InterfaceDeclaration, location); + typeParameters?: Array, heritageClauses?: Array, members?: Array + ): InterfaceDeclaration { + let node = createNode(SyntaxKind.InterfaceDeclaration); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -1330,8 +1323,8 @@ namespace ts { return node; } export function createTypeAliasDeclaration(decorators?: Array, modifiers?: Array, name?: Identifier, - typeParameters?: Array, type?: TypeNode, location?: TextRange): TypeAliasDeclaration { - let node = createNode(SyntaxKind.TypeAliasDeclaration, location); + typeParameters?: Array, type?: TypeNode): TypeAliasDeclaration { + let node = createNode(SyntaxKind.TypeAliasDeclaration); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -1350,9 +1343,9 @@ namespace ts { } return node; } - export function createEnumDeclaration(decorators?: Array, modifiers?: Array, name?: Identifier, members?: Array, - location?: TextRange): EnumDeclaration { - let node = createNode(SyntaxKind.EnumDeclaration, location); + export function createEnumDeclaration(decorators?: Array, modifiers?: Array, name?: Identifier, members?: Array + ): EnumDeclaration { + let node = createNode(SyntaxKind.EnumDeclaration); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -1370,8 +1363,8 @@ namespace ts { return node; } export function createModuleDeclaration(decorators?: Array, modifiers?: Array, name?: Identifier | LiteralExpression, - body?: ModuleBlock | ModuleDeclaration, location?: TextRange): ModuleDeclaration { - let node = createNode(SyntaxKind.ModuleDeclaration, location); + body?: ModuleBlock | ModuleDeclaration): ModuleDeclaration { + let node = createNode(SyntaxKind.ModuleDeclaration); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -1388,8 +1381,8 @@ namespace ts { } return node; } - export function createModuleBlock(statements?: Array, location?: TextRange): ModuleBlock { - let node = createNode(SyntaxKind.ModuleBlock, location); + export function createModuleBlock(statements?: Array): ModuleBlock { + let node = createNode(SyntaxKind.ModuleBlock); node.statements = statements && createNodeArray(statements) return node; } @@ -1400,8 +1393,8 @@ namespace ts { } return node; } - export function createCaseBlock(clauses?: Array, location?: TextRange): CaseBlock { - let node = createNode(SyntaxKind.CaseBlock, location); + export function createCaseBlock(clauses?: Array): CaseBlock { + let node = createNode(SyntaxKind.CaseBlock); node.clauses = clauses && createNodeArray(clauses) return node; } @@ -1413,8 +1406,8 @@ namespace ts { return node; } export function createImportEqualsDeclaration(decorators?: Array, modifiers?: Array, name?: Identifier, - moduleReference?: EntityName | ExternalModuleReference, location?: TextRange): ImportEqualsDeclaration { - let node = createNode(SyntaxKind.ImportEqualsDeclaration, location); + moduleReference?: EntityName | ExternalModuleReference): ImportEqualsDeclaration { + let node = createNode(SyntaxKind.ImportEqualsDeclaration); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -1432,8 +1425,8 @@ namespace ts { return node; } export function createImportDeclaration(decorators?: Array, modifiers?: Array, importClause?: ImportClause, - moduleSpecifier?: Expression, location?: TextRange): ImportDeclaration { - let node = createNode(SyntaxKind.ImportDeclaration, location); + moduleSpecifier?: Expression): ImportDeclaration { + let node = createNode(SyntaxKind.ImportDeclaration); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -1451,23 +1444,23 @@ namespace ts { } return node; } - export function createImportClause(name?: Identifier, namedBindings?: NamespaceImport | NamedImports, location?: TextRange): ImportClause { - let node = createNode(SyntaxKind.ImportClause, location); + export function createImportClause(name?: Identifier, namedBindings?: NamedImports | NamespaceImport): ImportClause { + let node = createNode(SyntaxKind.ImportClause); if (arguments.length) { node.name = name; node.namedBindings = namedBindings; } return node; } - export function updateImportClause(node: ImportClause, name: Identifier, namedBindings: NamespaceImport | NamedImports): ImportClause { + export function updateImportClause(node: ImportClause, name: Identifier, namedBindings: NamedImports | NamespaceImport): ImportClause { if (name !== node.name || namedBindings !== node.namedBindings) { let newNode = createImportClause(name, namedBindings); return updateFrom(node, newNode); } return node; } - export function createNamespaceImport(name?: Identifier, location?: TextRange): NamespaceImport { - let node = createNode(SyntaxKind.NamespaceImport, location); + export function createNamespaceImport(name?: Identifier): NamespaceImport { + let node = createNode(SyntaxKind.NamespaceImport); node.name = name; return node; } @@ -1478,8 +1471,8 @@ namespace ts { } return node; } - export function createNamedImports(elements?: Array, location?: TextRange): NamedImports { - let node = createNode(SyntaxKind.NamedImports, location); + export function createNamedImports(elements?: Array): NamedImports { + let node = createNode(SyntaxKind.NamedImports); node.elements = elements && createNodeArray(elements) return node; } @@ -1490,8 +1483,8 @@ namespace ts { } return node; } - export function createImportSpecifier(propertyName?: Identifier, name?: Identifier, location?: TextRange): ImportSpecifier { - let node = createNode(SyntaxKind.ImportSpecifier, location); + export function createImportSpecifier(propertyName?: Identifier, name?: Identifier): ImportSpecifier { + let node = createNode(SyntaxKind.ImportSpecifier); if (arguments.length) { node.propertyName = propertyName; node.name = name; @@ -1505,9 +1498,8 @@ namespace ts { } return node; } - export function createExportAssignment(decorators?: Array, modifiers?: Array, expression?: Expression, - location?: TextRange): ExportAssignment { - let node = createNode(SyntaxKind.ExportAssignment, location); + export function createExportAssignment(decorators?: Array, modifiers?: Array, expression?: Expression): ExportAssignment { + let node = createNode(SyntaxKind.ExportAssignment); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -1524,8 +1516,8 @@ namespace ts { return node; } export function createExportDeclaration(decorators?: Array, modifiers?: Array, exportClause?: NamedExports, - moduleSpecifier?: Expression, location?: TextRange): ExportDeclaration { - let node = createNode(SyntaxKind.ExportDeclaration, location); + moduleSpecifier?: Expression): ExportDeclaration { + let node = createNode(SyntaxKind.ExportDeclaration); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -1543,8 +1535,8 @@ namespace ts { } return node; } - export function createNamedExports(elements?: Array, location?: TextRange): NamedExports { - let node = createNode(SyntaxKind.NamedExports, location); + export function createNamedExports(elements?: Array): NamedExports { + let node = createNode(SyntaxKind.NamedExports); node.elements = elements && createNodeArray(elements) return node; } @@ -1555,8 +1547,8 @@ namespace ts { } return node; } - export function createExportSpecifier(propertyName?: Identifier, name?: Identifier, location?: TextRange): ExportSpecifier { - let node = createNode(SyntaxKind.ExportSpecifier, location); + export function createExportSpecifier(propertyName?: Identifier, name?: Identifier): ExportSpecifier { + let node = createNode(SyntaxKind.ExportSpecifier); if (arguments.length) { node.propertyName = propertyName; node.name = name; @@ -1570,8 +1562,8 @@ namespace ts { } return node; } - export function createMissingDeclaration(decorators?: Array, modifiers?: Array, location?: TextRange): MissingDeclaration { - let node = createNode(SyntaxKind.MissingDeclaration, location); + export function createMissingDeclaration(decorators?: Array, modifiers?: Array): MissingDeclaration { + let node = createNode(SyntaxKind.MissingDeclaration); if (arguments.length) { node.decorators = decorators && createNodeArray(decorators) setModifiers(node, modifiers); @@ -1586,8 +1578,8 @@ namespace ts { } return node; } - export function createExternalModuleReference(expression?: Expression, location?: TextRange): ExternalModuleReference { - let node = createNode(SyntaxKind.ExternalModuleReference, location); + export function createExternalModuleReference(expression?: Expression): ExternalModuleReference { + let node = createNode(SyntaxKind.ExternalModuleReference); node.expression = expression; return node; } @@ -1598,9 +1590,9 @@ namespace ts { } return node; } - export function createJsxElement(openingElement?: JsxOpeningElement, children?: Array, closingElement?: JsxClosingElement, - location?: TextRange): JsxElement { - let node = createNode(SyntaxKind.JsxElement, location); + export function createJsxElement(openingElement?: JsxOpeningElement, children?: Array, closingElement?: JsxClosingElement + ): JsxElement { + let node = createNode(SyntaxKind.JsxElement); if (arguments.length) { node.openingElement = openingElement; node.children = children && createNodeArray(children) @@ -1616,9 +1608,9 @@ namespace ts { } return node; } - export function createJsxSelfClosingElement(tagName?: EntityName, attributes?: Array, - location?: TextRange): JsxSelfClosingElement { - let node = createNode(SyntaxKind.JsxSelfClosingElement, location); + export function createJsxSelfClosingElement(tagName?: EntityName, attributes?: Array + ): JsxSelfClosingElement { + let node = createNode(SyntaxKind.JsxSelfClosingElement); if (arguments.length) { node.tagName = tagName; node.attributes = attributes && createNodeArray(attributes) @@ -1633,9 +1625,8 @@ namespace ts { } return node; } - export function createJsxOpeningElement(tagName?: EntityName, attributes?: Array, - location?: TextRange): JsxOpeningElement { - let node = createNode(SyntaxKind.JsxOpeningElement, location); + export function createJsxOpeningElement(tagName?: EntityName, attributes?: Array): JsxOpeningElement { + let node = createNode(SyntaxKind.JsxOpeningElement); if (arguments.length) { node.tagName = tagName; node.attributes = attributes && createNodeArray(attributes) @@ -1650,11 +1641,11 @@ namespace ts { } return node; } - export function createJsxText(location?: TextRange): JsxText { - return createNode(SyntaxKind.JsxText, location); + export function createJsxText(): JsxText { + return createNode(SyntaxKind.JsxText); } - export function createJsxClosingElement(tagName?: EntityName, location?: TextRange): JsxClosingElement { - let node = createNode(SyntaxKind.JsxClosingElement, location); + export function createJsxClosingElement(tagName?: EntityName): JsxClosingElement { + let node = createNode(SyntaxKind.JsxClosingElement); node.tagName = tagName; return node; } @@ -1665,8 +1656,8 @@ namespace ts { } return node; } - export function createJsxAttribute(name?: Identifier, initializer?: Expression, location?: TextRange): JsxAttribute { - let node = createNode(SyntaxKind.JsxAttribute, location); + export function createJsxAttribute(name?: Identifier, initializer?: Expression): JsxAttribute { + let node = createNode(SyntaxKind.JsxAttribute); if (arguments.length) { node.name = name; node.initializer = initializer; @@ -1680,8 +1671,8 @@ namespace ts { } return node; } - export function createJsxSpreadAttribute(expression?: Expression, location?: TextRange): JsxSpreadAttribute { - let node = createNode(SyntaxKind.JsxSpreadAttribute, location); + export function createJsxSpreadAttribute(expression?: Expression): JsxSpreadAttribute { + let node = createNode(SyntaxKind.JsxSpreadAttribute); node.expression = expression; return node; } @@ -1692,8 +1683,8 @@ namespace ts { } return node; } - export function createJsxExpression(expression?: Expression, location?: TextRange): JsxExpression { - let node = createNode(SyntaxKind.JsxExpression, location); + export function createJsxExpression(expression?: Expression): JsxExpression { + let node = createNode(SyntaxKind.JsxExpression); node.expression = expression; return node; } @@ -1704,8 +1695,8 @@ namespace ts { } return node; } - export function createCaseClause(expression?: Expression, statements?: Array, location?: TextRange): CaseClause { - let node = createNode(SyntaxKind.CaseClause, location); + export function createCaseClause(expression?: Expression, statements?: Array): CaseClause { + let node = createNode(SyntaxKind.CaseClause); if (arguments.length) { node.expression = expression; node.statements = statements && createNodeArray(statements) @@ -1719,8 +1710,8 @@ namespace ts { } return node; } - export function createDefaultClause(statements?: Array, location?: TextRange): DefaultClause { - let node = createNode(SyntaxKind.DefaultClause, location); + export function createDefaultClause(statements?: Array): DefaultClause { + let node = createNode(SyntaxKind.DefaultClause); node.statements = statements && createNodeArray(statements) return node; } @@ -1731,8 +1722,8 @@ namespace ts { } return node; } - export function createHeritageClause(types?: Array, location?: TextRange): HeritageClause { - let node = createNode(SyntaxKind.HeritageClause, location); + export function createHeritageClause(types?: Array): HeritageClause { + let node = createNode(SyntaxKind.HeritageClause); node.types = types && createNodeArray(types) return node; } @@ -1743,8 +1734,8 @@ namespace ts { } return node; } - export function createCatchClause(variableDeclaration?: VariableDeclaration, block?: Block, location?: TextRange): CatchClause { - let node = createNode(SyntaxKind.CatchClause, location); + export function createCatchClause(variableDeclaration?: VariableDeclaration, block?: Block): CatchClause { + let node = createNode(SyntaxKind.CatchClause); if (arguments.length) { node.variableDeclaration = variableDeclaration; node.block = block; @@ -1758,9 +1749,8 @@ namespace ts { } return node; } - export function createPropertyAssignment(name?: DeclarationName, questionToken?: Node, initializer?: Expression, - location?: TextRange): PropertyAssignment { - let node = createNode(SyntaxKind.PropertyAssignment, location); + export function createPropertyAssignment(name?: DeclarationName, questionToken?: Node, initializer?: Expression): PropertyAssignment { + let node = createNode(SyntaxKind.PropertyAssignment); if (arguments.length) { node.name = name; node.questionToken = questionToken; @@ -1775,9 +1765,8 @@ namespace ts { } return node; } - export function createShorthandPropertyAssignment(name?: Identifier, questionToken?: Node, - location?: TextRange): ShorthandPropertyAssignment { - let node = createNode(SyntaxKind.ShorthandPropertyAssignment, location); + export function createShorthandPropertyAssignment(name?: Identifier, questionToken?: Node): ShorthandPropertyAssignment { + let node = createNode(SyntaxKind.ShorthandPropertyAssignment); if (arguments.length) { node.name = name; node.questionToken = questionToken; @@ -1791,8 +1780,8 @@ namespace ts { } return node; } - export function createEnumMember(name?: DeclarationName, initializer?: Expression, location?: TextRange): EnumMember { - let node = createNode(SyntaxKind.EnumMember, location); + export function createEnumMember(name?: DeclarationName, initializer?: Expression): EnumMember { + let node = createNode(SyntaxKind.EnumMember); if (arguments.length) { node.name = name; node.initializer = initializer; @@ -1806,8 +1795,8 @@ namespace ts { } return node; } - export function createJSDocTypeExpression(type?: JSDocType, location?: TextRange): JSDocTypeExpression { - let node = createNode(SyntaxKind.JSDocTypeExpression, location); + export function createJSDocTypeExpression(type?: JSDocType): JSDocTypeExpression { + let node = createNode(SyntaxKind.JSDocTypeExpression); node.type = type; return node; } @@ -1818,14 +1807,14 @@ namespace ts { } return node; } - export function createJSDocAllType(location?: TextRange): JSDocAllType { - return createNode(SyntaxKind.JSDocAllType, location); + export function createJSDocAllType(): JSDocAllType { + return createNode(SyntaxKind.JSDocAllType); } - export function createJSDocUnknownType(location?: TextRange): JSDocUnknownType { - return createNode(SyntaxKind.JSDocUnknownType, location); + export function createJSDocUnknownType(): JSDocUnknownType { + return createNode(SyntaxKind.JSDocUnknownType); } - export function createJSDocArrayType(elementType?: JSDocType, location?: TextRange): JSDocArrayType { - let node = createNode(SyntaxKind.JSDocArrayType, location); + export function createJSDocArrayType(elementType?: JSDocType): JSDocArrayType { + let node = createNode(SyntaxKind.JSDocArrayType); node.elementType = elementType; return node; } @@ -1836,8 +1825,8 @@ namespace ts { } return node; } - export function createJSDocUnionType(types?: Array, location?: TextRange): JSDocUnionType { - let node = createNode(SyntaxKind.JSDocUnionType, location); + export function createJSDocUnionType(types?: Array): JSDocUnionType { + let node = createNode(SyntaxKind.JSDocUnionType); node.types = types && createNodeArray(types) return node; } @@ -1848,8 +1837,8 @@ namespace ts { } return node; } - export function createJSDocTupleType(types?: Array, location?: TextRange): JSDocTupleType { - let node = createNode(SyntaxKind.JSDocTupleType, location); + export function createJSDocTupleType(types?: Array): JSDocTupleType { + let node = createNode(SyntaxKind.JSDocTupleType); node.types = types && createNodeArray(types) return node; } @@ -1860,8 +1849,8 @@ namespace ts { } return node; } - export function createJSDocNullableType(type?: JSDocType, location?: TextRange): JSDocNullableType { - let node = createNode(SyntaxKind.JSDocNullableType, location); + export function createJSDocNullableType(type?: JSDocType): JSDocNullableType { + let node = createNode(SyntaxKind.JSDocNullableType); node.type = type; return node; } @@ -1872,8 +1861,8 @@ namespace ts { } return node; } - export function createJSDocNonNullableType(type?: JSDocType, location?: TextRange): JSDocNonNullableType { - let node = createNode(SyntaxKind.JSDocNonNullableType, location); + export function createJSDocNonNullableType(type?: JSDocType): JSDocNonNullableType { + let node = createNode(SyntaxKind.JSDocNonNullableType); node.type = type; return node; } @@ -1884,8 +1873,8 @@ namespace ts { } return node; } - export function createJSDocRecordType(members?: Array, location?: TextRange): JSDocRecordType { - let node = createNode(SyntaxKind.JSDocRecordType, location); + export function createJSDocRecordType(members?: Array): JSDocRecordType { + let node = createNode(SyntaxKind.JSDocRecordType); node.members = members && createNodeArray(members) return node; } @@ -1896,8 +1885,8 @@ namespace ts { } return node; } - export function createJSDocRecordMember(name?: Identifier | LiteralExpression, type?: JSDocType, location?: TextRange): JSDocRecordMember { - let node = createNode(SyntaxKind.JSDocRecordMember, location); + export function createJSDocRecordMember(name?: Identifier | LiteralExpression, type?: JSDocType): JSDocRecordMember { + let node = createNode(SyntaxKind.JSDocRecordMember); if (arguments.length) { node.name = name; node.type = type; @@ -1911,8 +1900,8 @@ namespace ts { } return node; } - export function createJSDocTypeReference(name?: EntityName, typeArguments?: Array, location?: TextRange): JSDocTypeReference { - let node = createNode(SyntaxKind.JSDocTypeReference, location); + export function createJSDocTypeReference(name?: EntityName, typeArguments?: Array): JSDocTypeReference { + let node = createNode(SyntaxKind.JSDocTypeReference); if (arguments.length) { node.name = name; node.typeArguments = typeArguments && createNodeArray(typeArguments) @@ -1926,8 +1915,8 @@ namespace ts { } return node; } - export function createJSDocOptionalType(type?: JSDocType, location?: TextRange): JSDocOptionalType { - let node = createNode(SyntaxKind.JSDocOptionalType, location); + export function createJSDocOptionalType(type?: JSDocType): JSDocOptionalType { + let node = createNode(SyntaxKind.JSDocOptionalType); node.type = type; return node; } @@ -1938,9 +1927,8 @@ namespace ts { } return node; } - export function createJSDocFunctionType(parameters?: Array, type?: JSDocType, - location?: TextRange): JSDocFunctionType { - let node = createNode(SyntaxKind.JSDocFunctionType, location); + export function createJSDocFunctionType(parameters?: Array, type?: JSDocType): JSDocFunctionType { + let node = createNode(SyntaxKind.JSDocFunctionType); if (arguments.length) { node.parameters = parameters && createNodeArray(parameters) node.type = type; @@ -1955,8 +1943,8 @@ namespace ts { } return node; } - export function createJSDocVariadicType(type?: JSDocType, location?: TextRange): JSDocVariadicType { - let node = createNode(SyntaxKind.JSDocVariadicType, location); + export function createJSDocVariadicType(type?: JSDocType): JSDocVariadicType { + let node = createNode(SyntaxKind.JSDocVariadicType); node.type = type; return node; } @@ -1967,8 +1955,8 @@ namespace ts { } return node; } - export function createJSDocConstructorType(type?: JSDocType, location?: TextRange): JSDocConstructorType { - let node = createNode(SyntaxKind.JSDocConstructorType, location); + export function createJSDocConstructorType(type?: JSDocType): JSDocConstructorType { + let node = createNode(SyntaxKind.JSDocConstructorType); node.type = type; return node; } @@ -1979,8 +1967,8 @@ namespace ts { } return node; } - export function createJSDocThisType(type?: JSDocType, location?: TextRange): JSDocThisType { - let node = createNode(SyntaxKind.JSDocThisType, location); + export function createJSDocThisType(type?: JSDocType): JSDocThisType { + let node = createNode(SyntaxKind.JSDocThisType); node.type = type; return node; } @@ -1991,8 +1979,8 @@ namespace ts { } return node; } - export function createJSDocComment(tags?: Array, location?: TextRange): JSDocComment { - let node = createNode(SyntaxKind.JSDocComment, location); + export function createJSDocComment(tags?: Array): JSDocComment { + let node = createNode(SyntaxKind.JSDocComment); node.tags = tags && createNodeArray(tags) return node; } @@ -2003,8 +1991,8 @@ namespace ts { } return node; } - export function createJSDocTag(atToken?: Node, tagName?: Identifier, location?: TextRange): JSDocTag { - let node = createNode(SyntaxKind.JSDocTag, location); + export function createJSDocTag(atToken?: Node, tagName?: Identifier): JSDocTag { + let node = createNode(SyntaxKind.JSDocTag); if (arguments.length) { node.atToken = atToken; node.tagName = tagName; @@ -2019,8 +2007,8 @@ namespace ts { return node; } export function createJSDocParameterTag(preParameterName?: Identifier, typeExpression?: JSDocTypeExpression, postParameterName?: Identifier, - atToken?: Node, tagName?: Identifier, location?: TextRange): JSDocParameterTag { - let node = createNode(SyntaxKind.JSDocParameterTag, location); + atToken?: Node, tagName?: Identifier): JSDocParameterTag { + let node = createNode(SyntaxKind.JSDocParameterTag); if (arguments.length) { node.preParameterName = preParameterName; node.typeExpression = typeExpression; @@ -2039,9 +2027,8 @@ namespace ts { } return node; } - export function createJSDocReturnTag(typeExpression?: JSDocTypeExpression, atToken?: Node, tagName?: Identifier, - location?: TextRange): JSDocReturnTag { - let node = createNode(SyntaxKind.JSDocReturnTag, location); + export function createJSDocReturnTag(typeExpression?: JSDocTypeExpression, atToken?: Node, tagName?: Identifier): JSDocReturnTag { + let node = createNode(SyntaxKind.JSDocReturnTag); if (arguments.length) { node.typeExpression = typeExpression; node.atToken = atToken; @@ -2056,9 +2043,8 @@ namespace ts { } return node; } - export function createJSDocTypeTag(typeExpression?: JSDocTypeExpression, atToken?: Node, tagName?: Identifier, - location?: TextRange): JSDocTypeTag { - let node = createNode(SyntaxKind.JSDocTypeTag, location); + export function createJSDocTypeTag(typeExpression?: JSDocTypeExpression, atToken?: Node, tagName?: Identifier): JSDocTypeTag { + let node = createNode(SyntaxKind.JSDocTypeTag); if (arguments.length) { node.typeExpression = typeExpression; node.atToken = atToken; @@ -2073,9 +2059,9 @@ namespace ts { } return node; } - export function createJSDocTemplateTag(typeParameters?: Array, atToken?: Node, tagName?: Identifier, - location?: TextRange): JSDocTemplateTag { - let node = createNode(SyntaxKind.JSDocTemplateTag, location); + export function createJSDocTemplateTag(typeParameters?: Array, atToken?: Node, tagName?: Identifier + ): JSDocTemplateTag { + let node = createNode(SyntaxKind.JSDocTemplateTag); if (arguments.length) { node.typeParameters = typeParameters && createNodeArray(typeParameters) node.atToken = atToken; @@ -2116,6 +2102,21 @@ namespace ts { export function isIdentifier(node: Node): node is Identifier { return node && node.kind === SyntaxKind.Identifier; } + export function isFalseKeyword(node: Node): node is LeftHandSideExpression { + return node && node.kind === SyntaxKind.FalseKeyword; + } + export function isNullKeyword(node: Node): node is LeftHandSideExpression { + return node && node.kind === SyntaxKind.NullKeyword; + } + export function isSuperKeyword(node: Node): node is LeftHandSideExpression { + return node && node.kind === SyntaxKind.SuperKeyword; + } + export function isThisKeyword(node: Node): node is LeftHandSideExpression { + return node && node.kind === SyntaxKind.ThisKeyword; + } + export function isTrueKeyword(node: Node): node is LeftHandSideExpression { + return node && node.kind === SyntaxKind.TrueKeyword; + } export function isQualifiedName(node: Node): node is QualifiedName { return node && node.kind === SyntaxKind.QualifiedName; } @@ -2293,7 +2294,7 @@ namespace ts { export function isVariableStatement(node: Node): node is VariableStatement { return node && node.kind === SyntaxKind.VariableStatement; } - export function isEmptyStatement(node: Node): node is Statement { + export function isEmptyStatement(node: Node): node is EmptyStatement { return node && node.kind === SyntaxKind.EmptyStatement; } export function isExpressionStatement(node: Node): node is ExpressionStatement { @@ -2341,7 +2342,7 @@ namespace ts { export function isTryStatement(node: Node): node is TryStatement { return node && node.kind === SyntaxKind.TryStatement; } - export function isDebuggerStatement(node: Node): node is Statement { + export function isDebuggerStatement(node: Node): node is DebuggerStatement { return node && node.kind === SyntaxKind.DebuggerStatement; } export function isVariableDeclaration(node: Node): node is VariableDeclaration { @@ -2521,4 +2522,338 @@ namespace ts { export function isJSDocTemplateTag(node: Node): node is JSDocTemplateTag { return node && node.kind === SyntaxKind.JSDocTemplateTag; } + export function isEntityName(node: Node): node is EntityName { + if (node) { + switch (node.kind) { + case SyntaxKind.Identifier: + case SyntaxKind.QualifiedName: + return true; + } + } + return false; + } + export function isBindingPatternOrIdentifier(node: Node): node is BindingPattern | Identifier { + if (node) { + switch (node.kind) { + case SyntaxKind.ObjectBindingPattern: + case SyntaxKind.ArrayBindingPattern: + case SyntaxKind.Identifier: + return true; + } + } + return false; + } + export function isUnaryExpression(node: Node): node is UnaryExpression { + if (node) { + switch (node.kind) { + case SyntaxKind.Identifier: + case SyntaxKind.StringLiteral: + case SyntaxKind.PrefixUnaryExpression: + case SyntaxKind.PostfixUnaryExpression: + case SyntaxKind.TrueKeyword: + case SyntaxKind.FalseKeyword: + case SyntaxKind.NullKeyword: + case SyntaxKind.ThisKeyword: + case SyntaxKind.SuperKeyword: + case SyntaxKind.DeleteExpression: + case SyntaxKind.TypeOfExpression: + case SyntaxKind.VoidExpression: + case SyntaxKind.AwaitExpression: + case SyntaxKind.FunctionExpression: + case SyntaxKind.NumericLiteral: + case SyntaxKind.RegularExpressionLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.TemplateHead: + case SyntaxKind.TemplateMiddle: + case SyntaxKind.TemplateTail: + case SyntaxKind.TemplateExpression: + case SyntaxKind.ParenthesizedExpression: + case SyntaxKind.ArrayLiteralExpression: + case SyntaxKind.ObjectLiteralExpression: + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.ElementAccessExpression: + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + case SyntaxKind.TaggedTemplateExpression: + case SyntaxKind.TypeAssertionExpression: + case SyntaxKind.JsxElement: + case SyntaxKind.JsxSelfClosingElement: + case SyntaxKind.ClassExpression: + return true; + } + } + return false; + } + export function isBlockOrExpression(node: Node): node is Block | Expression { + if (node) { + switch (node.kind) { + case SyntaxKind.Block: + case SyntaxKind.Identifier: + case SyntaxKind.StringLiteral: + case SyntaxKind.OmittedExpression: + case SyntaxKind.PrefixUnaryExpression: + case SyntaxKind.PostfixUnaryExpression: + case SyntaxKind.TrueKeyword: + case SyntaxKind.FalseKeyword: + case SyntaxKind.NullKeyword: + case SyntaxKind.ThisKeyword: + case SyntaxKind.SuperKeyword: + case SyntaxKind.DeleteExpression: + case SyntaxKind.TypeOfExpression: + case SyntaxKind.VoidExpression: + case SyntaxKind.AwaitExpression: + case SyntaxKind.YieldExpression: + case SyntaxKind.BinaryExpression: + case SyntaxKind.ConditionalExpression: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.NumericLiteral: + case SyntaxKind.RegularExpressionLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.TemplateHead: + case SyntaxKind.TemplateMiddle: + case SyntaxKind.TemplateTail: + case SyntaxKind.TemplateExpression: + case SyntaxKind.ParenthesizedExpression: + case SyntaxKind.ArrayLiteralExpression: + case SyntaxKind.SpreadElementExpression: + case SyntaxKind.ObjectLiteralExpression: + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.ElementAccessExpression: + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + case SyntaxKind.TaggedTemplateExpression: + case SyntaxKind.AsExpression: + case SyntaxKind.TypeAssertionExpression: + case SyntaxKind.JsxElement: + case SyntaxKind.JsxOpeningElement: + case SyntaxKind.JsxSelfClosingElement: + case SyntaxKind.JsxExpression: + case SyntaxKind.ClassExpression: + return true; + } + } + return false; + } + export function isLiteralExpression(node: Node): node is LiteralExpression { + if (node) { + switch (node.kind) { + case SyntaxKind.StringLiteral: + case SyntaxKind.NumericLiteral: + case SyntaxKind.RegularExpressionLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.TemplateHead: + case SyntaxKind.TemplateMiddle: + case SyntaxKind.TemplateTail: + return true; + } + } + return false; + } + export function isObjectLiteralElement(node: Node): node is ObjectLiteralElement { + if (node) { + switch (node.kind) { + case SyntaxKind.PropertyAssignment: + case SyntaxKind.ShorthandPropertyAssignment: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return true; + } + } + return false; + } + export function isLiteralExpressionOrTemplateExpression(node: Node): node is LiteralExpression | TemplateExpression { + if (node) { + switch (node.kind) { + case SyntaxKind.StringLiteral: + case SyntaxKind.NumericLiteral: + case SyntaxKind.RegularExpressionLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.TemplateHead: + case SyntaxKind.TemplateMiddle: + case SyntaxKind.TemplateTail: + case SyntaxKind.TemplateExpression: + return true; + } + } + return false; + } + export function isJsxChild(node: Node): node is JsxChild { + if (node) { + switch (node.kind) { + case SyntaxKind.JsxText: + case SyntaxKind.JsxExpression: + case SyntaxKind.JsxElement: + case SyntaxKind.JsxSelfClosingElement: + return true; + } + } + return false; + } + export function isJsxAttributeOrJsxSpreadAttribute(node: Node): node is JsxAttribute | JsxSpreadAttribute { + if (node) { + switch (node.kind) { + case SyntaxKind.JsxAttribute: + case SyntaxKind.JsxSpreadAttribute: + return true; + } + } + return false; + } + export function isExpressionOrVariableDeclarationList(node: Node): node is Expression | VariableDeclarationList { + if (node) { + switch (node.kind) { + case SyntaxKind.Identifier: + case SyntaxKind.StringLiteral: + case SyntaxKind.OmittedExpression: + case SyntaxKind.PrefixUnaryExpression: + case SyntaxKind.PostfixUnaryExpression: + case SyntaxKind.TrueKeyword: + case SyntaxKind.FalseKeyword: + case SyntaxKind.NullKeyword: + case SyntaxKind.ThisKeyword: + case SyntaxKind.SuperKeyword: + case SyntaxKind.DeleteExpression: + case SyntaxKind.TypeOfExpression: + case SyntaxKind.VoidExpression: + case SyntaxKind.AwaitExpression: + case SyntaxKind.YieldExpression: + case SyntaxKind.BinaryExpression: + case SyntaxKind.ConditionalExpression: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.NumericLiteral: + case SyntaxKind.RegularExpressionLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.TemplateHead: + case SyntaxKind.TemplateMiddle: + case SyntaxKind.TemplateTail: + case SyntaxKind.TemplateExpression: + case SyntaxKind.ParenthesizedExpression: + case SyntaxKind.ArrayLiteralExpression: + case SyntaxKind.SpreadElementExpression: + case SyntaxKind.ObjectLiteralExpression: + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.ElementAccessExpression: + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + case SyntaxKind.TaggedTemplateExpression: + case SyntaxKind.AsExpression: + case SyntaxKind.TypeAssertionExpression: + case SyntaxKind.JsxElement: + case SyntaxKind.JsxOpeningElement: + case SyntaxKind.JsxSelfClosingElement: + case SyntaxKind.JsxExpression: + case SyntaxKind.ClassExpression: + case SyntaxKind.VariableDeclarationList: + return true; + } + } + return false; + } + export function isCaseOrDefaultClause(node: Node): node is CaseOrDefaultClause { + if (node) { + switch (node.kind) { + case SyntaxKind.CaseClause: + case SyntaxKind.DefaultClause: + return true; + } + } + return false; + } + export function isClassElement(node: Node): node is ClassElement { + if (node) { + switch (node.kind) { + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.Constructor: + case SyntaxKind.SemicolonClassElement: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.IndexSignature: + return true; + } + } + return false; + } + export function isIdentifierOrLiteralExpression(node: Node): node is Identifier | LiteralExpression { + if (node) { + switch (node.kind) { + case SyntaxKind.Identifier: + case SyntaxKind.StringLiteral: + case SyntaxKind.NumericLiteral: + case SyntaxKind.RegularExpressionLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.TemplateHead: + case SyntaxKind.TemplateMiddle: + case SyntaxKind.TemplateTail: + return true; + } + } + return false; + } + export function isModuleBlockOrModuleDeclaration(node: Node): node is ModuleBlock | ModuleDeclaration { + if (node) { + switch (node.kind) { + case SyntaxKind.ModuleBlock: + case SyntaxKind.ModuleDeclaration: + return true; + } + } + return false; + } + export function isEntityNameOrExternalModuleReference(node: Node): node is EntityName | ExternalModuleReference { + if (node) { + switch (node.kind) { + case SyntaxKind.Identifier: + case SyntaxKind.QualifiedName: + case SyntaxKind.ExternalModuleReference: + return true; + } + } + return false; + } + export function isNamedImportsOrNamespaceImport(node: Node): node is NamedImports | NamespaceImport { + if (node) { + switch (node.kind) { + case SyntaxKind.NamedImports: + case SyntaxKind.NamespaceImport: + return true; + } + } + return false; + } + export function isImportOrExportSpecifier(node: Node): node is ImportOrExportSpecifier { + if (node) { + switch (node.kind) { + case SyntaxKind.ImportSpecifier: + case SyntaxKind.ExportSpecifier: + return true; + } + } + return false; + } + export function isJSDocType(node: Node): node is JSDocType { + if (node) { + switch (node.kind) { + case SyntaxKind.JSDocAllType: + case SyntaxKind.JSDocUnknownType: + case SyntaxKind.JSDocArrayType: + case SyntaxKind.JSDocUnionType: + case SyntaxKind.JSDocTupleType: + case SyntaxKind.JSDocNonNullableType: + case SyntaxKind.JSDocNullableType: + case SyntaxKind.JSDocRecordType: + case SyntaxKind.JSDocTypeReference: + case SyntaxKind.JSDocOptionalType: + case SyntaxKind.JSDocFunctionType: + case SyntaxKind.JSDocVariadicType: + case SyntaxKind.JSDocConstructorType: + case SyntaxKind.JSDocThisType: + return true; + } + } + return false; + } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1deb52501cb..e1efdf68167 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -443,6 +443,7 @@ namespace ts { // @factoryhidden("jsDocComment", true) // @factoryhidden("nextContainer", true) // @factoryorder("decorators", "modifiers") + // @nofactoryanynodetest export interface Node extends TextRange { kind: SyntaxKind; flags: NodeFlags; @@ -485,10 +486,12 @@ namespace ts { export type EntityName = Identifier | QualifiedName; + // @nofactoryanynodetest export type DeclarationName = Identifier | LiteralExpression | ComputedPropertyName | BindingPattern; // @factoryhidden("decorators", false) // @factoryhidden("modifiers", false) + // @nofactoryanynodetest export interface Declaration extends Node { _declarationBrand: any; name?: DeclarationName; @@ -569,7 +572,7 @@ namespace ts { } // @kind(SyntaxKind.PropertySignature) - export interface PropertySignature extends Declaration, ClassElement { + export interface PropertySignature extends Declaration { name: DeclarationName; // Declared property name // @factoryparam questionToken?: Node; // Present on optional property @@ -578,7 +581,8 @@ namespace ts { // @kind(SyntaxKind.PropertyDeclaration) // @factoryorder("decorators", "modifiers", "name", "questionToken", "type", "initializer") - export interface PropertyDeclaration extends PropertySignature { + export interface PropertyDeclaration extends PropertySignature, ClassElement { + name: DeclarationName; // Declared property name initializer?: Expression; // Optional initializer } @@ -664,7 +668,7 @@ namespace ts { // @factoryhidden("asteriskToken", true) // @factoryhidden("body", true) // @factoryorder("decorators", "modifiers", "asteriskToken", "name", "questionToken", "typeParameters", "parameters", "type") - export interface MethodSignature extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement { + export interface MethodSignature extends FunctionLikeDeclaration { } // Note that a MethodDeclaration is considered both a ClassElement and an ObjectLiteralElement. @@ -680,7 +684,7 @@ namespace ts { // @factoryhidden("questionToken", true) // @factoryhidden("body", false) // @factoryorder("decorators", "modifiers", "asteriskToken", "name", "typeParameters", "parameters", "type", "body") - export interface MethodDeclaration extends MethodSignature { + export interface MethodDeclaration extends MethodSignature, ClassElement, ObjectLiteralElement { body?: Block; } @@ -733,6 +737,7 @@ namespace ts { _indexSignatureDeclarationBrand: any; } + // @nofactoryanynodetest export interface TypeNode extends Node { _typeNodeBrand: any; } @@ -818,6 +823,7 @@ namespace ts { // checker actually thinks you have something of the right type. Note: the brands are // never actually given values. At runtime they have zero cost. // @kind(SyntaxKind.OmittedExpression) + // @nofactoryanynodetest export interface Expression extends Node { _expressionBrand: any; contextualType?: Type; // Used to temporarily assign a contextual type during overload resolution @@ -845,6 +851,12 @@ namespace ts { _postfixExpressionBrand: any; } + // @kind(SyntaxKind.TrueKeyword, { create: false }) + // @kind(SyntaxKind.FalseKeyword, { create: false }) + // @kind(SyntaxKind.NullKeyword, { create: false }) + // @kind(SyntaxKind.ThisKeyword, { create: false }) + // @kind(SyntaxKind.SuperKeyword, { create: false }) + // @nofactoryanynodetest export interface LeftHandSideExpression extends PostfixExpression { _leftHandSideExpressionBrand: any; } @@ -1081,11 +1093,16 @@ namespace ts { export type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement; - // @kind(SyntaxKind.EmptyStatement) - // @kind(SyntaxKind.DebuggerStatement); + // @nofactoryanynodetest export interface Statement extends Node { _statementBrand: any; } + + // @kind(SyntaxKind.EmptyStatement) + export type EmptyStatement = Statement; + + // @kind(SyntaxKind.DebuggerStatement) + export type DebuggerStatement = Statement; // @kind(SyntaxKind.MissingDeclaration) // @factoryhidden("name", true) @@ -1471,7 +1488,7 @@ namespace ts { // @factoryhidden("initializer", true) // @factoryhidden("decorators", true) // @factoryhidden("modifiers", true) - export interface JSDocRecordMember extends PropertyDeclaration { + export interface JSDocRecordMember extends PropertySignature { name: Identifier | LiteralExpression, type?: JSDocType } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 2a1778cb19c..eacfc8108ae 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1100,7 +1100,7 @@ namespace ts { return false; } - export function isDeclaration(node: Node): boolean { + export function isDeclaration(node: Node): node is Declaration { switch (node.kind) { case SyntaxKind.ArrowFunction: case SyntaxKind.BindingElement: @@ -1135,7 +1135,7 @@ namespace ts { return false; } - export function isStatement(n: Node): boolean { + export function isStatement(n: Node): n is Statement { switch (n.kind) { case SyntaxKind.BreakStatement: case SyntaxKind.ContinueStatement: @@ -1162,21 +1162,6 @@ namespace ts { } } - export function isClassElement(n: Node): boolean { - switch (n.kind) { - case SyntaxKind.Constructor: - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.MethodSignature: - case SyntaxKind.IndexSignature: - return true; - default: - return false; - } - } - // True if the given identifier, string literal, or number literal is the name of a declaration node export function isDeclarationName(name: Node): boolean { if (name.kind !== SyntaxKind.Identifier && name.kind !== SyntaxKind.StringLiteral && name.kind !== SyntaxKind.NumericLiteral) { @@ -1896,7 +1881,7 @@ namespace ts { return 0; } - export function isLeftHandSideExpression(expr: Expression): boolean { + export function isLeftHandSideExpression(expr: Node): boolean { if (expr) { switch (expr.kind) { case SyntaxKind.PropertyAccessExpression: