Progress on downlevel transformations

This commit is contained in:
Ron Buckton 2015-08-07 09:39:18 -07:00
parent 92a7bb0462
commit 558fc40303
28 changed files with 3985 additions and 2412 deletions

View file

@ -44,6 +44,7 @@ var compilerSources = [
"transform.ts",
"transform.generated.ts",
"transforms/es6.ts",
"transforms/es5.ts",
"declarationEmitter.ts",
"emitter.ts",
"program.ts",
@ -66,6 +67,7 @@ var servicesSources = [
"transform.ts",
"transform.generated.ts",
"transforms/es6.ts",
"transforms/es5.ts",
"declarationEmitter.ts",
"emitter.ts",
"program.ts",
@ -209,6 +211,7 @@ function concatenateFiles(destinationFile, sourceFiles) {
}
var useDebugMode = true;
var useTransforms = false;
var host = (process.env.host || process.env.TYPESCRIPT_HOST || "node");
var compilerFilename = "tsc.js";
/* Compiles a file from a list of sources
@ -236,7 +239,9 @@ function compileFile(outFile, sources, prereqs, opts, callback) {
, noResolve = opts && opts.noResolve
, stripInternal = opts && opts.stripInternal
, experimentalDecorators = opts && opts.experimentalDecorators
, target = opts && opts.target;
, experimentalTransforms = opts && opts.experimentalTransforms
, target = opts && opts.target
, diagnostics = opts && opts.diagnostics;
var dir = useBuiltCompiler ? builtLocalDirectory : LKGDirectory;
var options = "--module commonjs -noImplicitAny";
@ -279,9 +284,17 @@ function compileFile(outFile, sources, prereqs, opts, callback) {
options += " --experimentalDecorators";
}
if (experimentalTransforms || (useBuiltCompiler && useTransforms)) {
options += " --experimentalTransforms";
}
if (target) {
options += " --target " + target;
}
if (diagnostics) {
options += " --diagnostics";
}
var cmd = host + " " + dir + compilerFilename + " " + options + " ";
cmd = cmd + sources.join(" ");
@ -444,6 +457,10 @@ task("setDebugMode", function() {
useDebugMode = true;
});
task("setTransforms", function() {
useTransforms = true;
});
task("configure-nightly", [configureNightlyJs], function() {
var cmd = "node " + configureNightlyJs + " " + packageJson + " " + programTs;
console.log(cmd);
@ -478,7 +495,7 @@ compileFile(servicesFile, servicesSources, [builtLocalDirectory, copyright].conc
preserveConstEnums: true,
keepComments: true,
noResolve: false,
stripInternal: true,
stripInternal: true
}, /*callback*/ function () {
jake.cpR(servicesFile, nodePackageFile, {silent: true});
@ -491,7 +508,6 @@ compileFile(servicesFile, servicesSources, [builtLocalDirectory, copyright].conc
fs.writeFileSync(nodeDefinitionsFile, definitionFileContents);
});
var serverFile = path.join(builtLocalDirectory, "tsserver.js");
compileFile(serverFile, serverSources,[builtLocalDirectory, copyright].concat(serverSources), {
prefixes: [copyright],
@ -590,7 +606,15 @@ directory(builtLocalDirectory);
// Task to build the tests infrastructure using the built compiler
var run = path.join(builtLocalDirectory, "run.js");
compileFile(run, harnessSources, [builtLocalDirectory, tscFile].concat(libraryTargets).concat(harnessSources), {
useBuiltCompiler: true
useBuiltCompiler: true,
diagnostics: true
});
var run2 = path.join(builtLocalDirectory, "run-tx.js");
compileFile(run2, harnessSources, [builtLocalDirectory, tscFile].concat(libraryTargets).concat(harnessSources), {
useBuiltCompiler: true,
experimentalTransforms: true,
diagnostics: true
});
var internalTests = "internal/";
@ -607,6 +631,9 @@ var refTest262Baseline = path.join(internalTests, "baselines/test262/reference")
desc("Builds the test infrastructure using the built compiler");
task("tests", ["local", run].concat(libraryTargets));
// Temporary task created to compare transform output on typescriptServices.js
task("tx", ["generate-diagnostics", "generate-factory", "lib", tscFile, run, run2]);
function exec(cmd, completeHandler, errorHandler) {
var ex = jake.createExec([cmd], {windowsVerbatimArguments: true});
// Add listeners for output and error

View file

@ -752,44 +752,44 @@ function generateTransform(outputFile: string) {
sys.writeFile(outputFile, writer.getText());
function writeVisitNodesFunctions() {
for (let typeName in memberTypeUsages) {
if (hasProperty(memberTypeUsages, typeName)) {
writeVisitNodeFunction(typeName);
}
}
for (let typeName in nodeArrayTypeUsages) {
if (getProperty(nodeArrayTypeUsages, typeName)) {
writeVisitNodesFunction(typeName);
}
}
// for (let typeName in memberTypeUsages) {
// if (hasProperty(memberTypeUsages, typeName)) {
// writeVisitNodeFunction(typeName);
// }
// }
// for (let typeName in nodeArrayTypeUsages) {
// if (getProperty(nodeArrayTypeUsages, typeName)) {
// writeVisitNodesFunction(typeName);
// }
// }
}
function writeVisitNodeFunction(typeName: string) {
if (typeName === "Node") {
return;
}
// if (typeName === "Node") {
// return;
// }
// Skip the visit function for this node if it is defined in transform.ts
if (resolveQualifiedName(transformSourceFile, `ts.transform.visit${typeNameToMethodNameSuffix(typeName)}`, SymbolFlags.Function)) {
return;
}
// // Skip the visit function for this node if it is defined in transform.ts
// if (resolveQualifiedName(transformSourceFile, `ts.transform.visit${typeNameToMethodNameSuffix(typeName)}`, SymbolFlags.Function)) {
// return;
// }
writer.write(`export function visit${typeNameToMethodNameSuffix(typeName)}(context: VisitorContext, node: ${typeName}, visitor: Visitor): ${typeName} {`);
writer.writeLine();
writer.increaseIndent();
// writer.write(`export function visit${typeNameToMethodNameSuffix(typeName)}(context: VisitorContext, node: ${typeName}, visitor: Visitor, mutator?: NodeWriter<${typeName}>): ${typeName} {`);
// writer.writeLine();
// writer.increaseIndent();
writer.write(`let visited = visit(context, node, visitor);`);
writer.writeLine();
// writer.write(`let visited = visit(context, node, visitor, mutator);`);
// writer.writeLine();
writer.write(`Debug.assert(!visited || is${typeNameToMethodNameSuffix(typeName)}(visited), "Wrong node kind after visit.");`);
writer.writeLine();
// writer.write(`Debug.assert(!visited || is${typeNameToMethodNameSuffix(typeName)}(visited), "Wrong node kind after visit.");`);
// writer.writeLine();
writer.write(`return <${typeName}>visited;`);
writer.writeLine();
// writer.write(`return <${typeName}>visited;`);
// writer.writeLine();
writer.decreaseIndent();
writer.write(`}`);
writer.writeLine();
// writer.decreaseIndent();
// writer.write(`}`);
// writer.writeLine();
}
function writeVisitNodesFunction(typeName: string) {
@ -802,7 +802,7 @@ function generateTransform(outputFile: string) {
return;
}
writer.write(`export function visitNodeArrayOf${typeNameToMethodNameSuffix(typeName)}(context: VisitorContext, nodes: Array<${typeName}>, visitor: Visitor): NodeArray<${typeName}> {`);
writer.write(`export function visitNodeArrayOf${typeNameToMethodNameSuffix(typeName)}(context: VisitorContext, nodes: Array<${typeName}>, visitor: (context: VisitorContext, input: Node, write: (node: Node) => void) => void): NodeArray<${typeName}> {`);
writer.writeLine();
writer.increaseIndent();
@ -815,15 +815,15 @@ function generateTransform(outputFile: string) {
}
function writeAcceptFunction() {
writer.write(`export function accept(context: VisitorContext, node: Node, visitor: Visitor): Node {`);
writer.write(`export function accept(context: VisitorContext, node: Node, visitor: Visitor, write: (node: Node) => void): void {`);
writer.writeLine();
writer.increaseIndent();
writer.write(`if (!node || !visitor) {`);
writer.write(`if (!node) {`);
writer.writeLine();
writer.increaseIndent();
writer.write(`return node;`);
writer.write(`return;`);
writer.writeLine();
writer.decreaseIndent();
@ -843,7 +843,7 @@ function generateTransform(outputFile: string) {
writer.writeLine();
writer.increaseIndent();
writer.write(`return factory.update${syntaxNode.kindName}(`);
writer.write(`return write(factory.update${syntaxNode.kindName}(`);
writer.writeLine();
writer.increaseIndent();
writer.write(`<${syntaxNode.typeName}>node`);
@ -855,15 +855,26 @@ function generateTransform(outputFile: string) {
writer.write(`, `);
writer.writeLine();
let visitorFunction =
member.visitorFunction ? member.visitorFunction :
member.isNodeArray || member.isModifiersArray ? `visitNodeArrayOf${typeNameToMethodNameSuffix(member.elementTypeName)}` :
`visit${typeNameToMethodNameSuffix(member.typeName)}`;
writer.write(`${visitorFunction}(context, (<${syntaxNode.typeName}>node).${member.propertyName}, visitor)`);
if (member.typeName === "Node") {
writer.write(`(<${syntaxNode.typeName}>node).${member.propertyName}`);
}
else {
// let visitorFunction =
// member.visitorFunction ? member.visitorFunction :
// member.isNodeArray || member.isModifiersArray ? `visitNodeArrayOf${typeNameToMethodNameSuffix(member.elementTypeName)}` :
// `visit${typeNameToMethodNameSuffix(member.typeName)}`;
let visitorFunction =
member.visitorFunction ? member.visitorFunction :
member.isNodeArray || member.isModifiersArray ? `<NodeArray<${member.elementTypeName}>>visitNodes` :
`<${member.typeName}>visitNode`;
writer.write(`${visitorFunction}(context, (<${syntaxNode.typeName}>node).${member.propertyName}, visitor)`);
}
}
writer.write(`);`);
writer.write(`));`);
writer.writeLine();
writer.decreaseIndent();
writer.decreaseIndent();
@ -872,7 +883,7 @@ function generateTransform(outputFile: string) {
writer.write(`default:`);
writer.writeLine();
writer.increaseIndent();
writer.write(`return node;`);
writer.write(`return write(node);`);
writer.writeLine();
writer.decreaseIndent();
writer.decreaseIndent();

View file

@ -1387,8 +1387,13 @@ namespace ts {
return true;
}
}
function isEntityNameOrExpression(node: Node): node is EntityName | Expression {
return isEntityName(node) || isExpression(node);
}
function isEntityNameVisible(entityName: EntityName | Expression, enclosingDeclaration: Node): SymbolVisibilityResult {
entityName = getOriginalNodeIf(entityName, isEntityNameOrExpression);
// get symbol of the first identifier of the entityName
let meaning: SymbolFlags;
if (entityName.parent.kind === SyntaxKind.TypeQuery) {
@ -2007,6 +2012,7 @@ namespace ts {
}
function isDeclarationVisible(node: Declaration): boolean {
node = getOriginalNodeIf(node, isDeclaration);
function getContainingExternalModule(node: Node) {
for (; node; node = node.parent) {
if (node.kind === SyntaxKind.ModuleDeclaration) {
@ -2155,6 +2161,7 @@ namespace ts {
}
function collectLinkedAliases(node: Identifier): Node[] {
node = getOriginalNodeIf(node, isIdentifier);
let exportSymbol: Symbol;
if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) {
exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node);
@ -4364,11 +4371,11 @@ namespace ts {
return getInferredType(context, i);
}
}
return t;
return t;
};
mapper.context = context;
return mapper;
return mapper;
}
function identityMapper(type: Type): Type {
@ -13815,7 +13822,7 @@ namespace ts {
else if ((entityName.parent.kind === SyntaxKind.JsxOpeningElement) || (entityName.parent.kind === SyntaxKind.JsxSelfClosingElement)) {
return getJsxElementTagSymbol(<JsxOpeningLikeElement>entityName.parent);
}
else if (isExpression(entityName)) {
else if (isPartOfExpression(entityName)) {
if (nodeIsMissing(entityName)) {
// Missing entity name.
return undefined;
@ -13953,7 +13960,7 @@ namespace ts {
return getTypeFromTypeNode(<TypeNode>node);
}
if (isExpression(node)) {
if (isPartOfExpression(node)) {
return getTypeOfExpression(<Expression>node);
}
@ -14055,6 +14062,7 @@ namespace ts {
// When resolved as an expression identifier, if the given node references an exported entity, return the declaration
// node of the exported entity's container. Otherwise, return undefined.
function getReferencedExportContainer(node: Identifier): SourceFile | ModuleDeclaration | EnumDeclaration {
node = getOriginalNodeIf(node, isIdentifier);
let symbol = getReferencedValueSymbol(node);
if (symbol) {
if (symbol.flags & SymbolFlags.ExportValue) {
@ -14084,6 +14092,7 @@ namespace ts {
// When resolved as an expression identifier, if the given node references an import, return the declaration of
// that import. Otherwise, return undefined.
function getReferencedImportDeclaration(node: Identifier): Declaration {
node = getOriginalNodeIf(node, isIdentifier);
let symbol = getReferencedValueSymbol(node);
return symbol && symbol.flags & SymbolFlags.Alias ? getDeclarationOfAliasSymbol(symbol) : undefined;
}
@ -14116,6 +14125,7 @@ namespace ts {
// When resolved as an expression identifier, if the given node references a nested block scoped entity with
// a name that hides an existing name, return the declaration of that entity. Otherwise, return undefined.
function getReferencedNestedRedeclaration(node: Identifier): Declaration {
node = getOriginalNodeIf(node, isIdentifier);
let symbol = getReferencedValueSymbol(node);
return symbol && isNestedRedeclarationSymbol(symbol) ? symbol.valueDeclaration : undefined;
}
@ -14123,10 +14133,11 @@ namespace ts {
// Return true if the given node is a declaration of a nested block scoped entity with a name that hides an
// existing name.
function isNestedRedeclaration(node: Declaration): boolean {
return isNestedRedeclarationSymbol(getSymbolOfNode(node));
return isNestedRedeclarationSymbol(getSymbolOfNode(getOriginalNode(node)));
}
function isValueAliasDeclaration(node: Node): boolean {
node = getOriginalNode(node);
switch (node.kind) {
case SyntaxKind.ImportEqualsDeclaration:
case SyntaxKind.ImportClause:
@ -14144,6 +14155,7 @@ namespace ts {
}
function isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean {
node = getOriginalNodeIf(node, isImportEqualsDeclaration);
if (node.parent.kind !== SyntaxKind.SourceFile || !isInternalModuleImportEqualsDeclaration(node)) {
// parent is not source file or it is not reference to internal module
return false;
@ -14171,6 +14183,7 @@ namespace ts {
}
function isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean {
node = getOriginalNode(node);
if (isAliasSymbolDeclaration(node)) {
let symbol = getSymbolOfNode(node);
if (getSymbolLinks(symbol).referenced) {
@ -14185,6 +14198,7 @@ namespace ts {
}
function isImplementationOfOverload(node: FunctionLikeDeclaration) {
node = getOriginalNodeIf(node, isFunctionLike);
if (nodeIsPresent(node.body)) {
let symbol = getSymbolOfNode(node);
let signaturesOfSymbol = getSignaturesOfSymbol(symbol);
@ -14206,6 +14220,7 @@ namespace ts {
}
function getNodeCheckFlags(node: Node): NodeCheckFlags {
node = getOriginalNode(node);
return getNodeLinks(node).flags;
}
@ -14213,8 +14228,13 @@ namespace ts {
computeEnumMemberValues(<EnumDeclaration>node.parent);
return getNodeLinks(node).enumMemberValue;
}
function isEnumMemberOrPropertyAccessExpressionOrElementAccessExpression(node: Node): node is EnumMember | PropertyAccessExpression | ElementAccessExpression {
return isEnumMember(node) || isPropertyAccessExpression(node) || isElementAccessExpression(node);
}
function getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number {
node = getOriginalNodeIf(node, isEnumMemberOrPropertyAccessExpressionOrElementAccessExpression);
if (node.kind === SyntaxKind.EnumMember) {
return getEnumMemberValue(<EnumMember>node);
}
@ -14309,12 +14329,14 @@ namespace ts {
}
function getReferencedValueDeclaration(reference: Identifier): Declaration {
reference = getOriginalNodeIf(reference, isIdentifier);
Debug.assert(!nodeIsSynthesized(reference));
let symbol = getReferencedValueSymbol(reference);
return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration;
}
function getBlockScopedVariableId(n: Identifier): number {
n = getOriginalNodeIf(n, isIdentifier);
Debug.assert(!nodeIsSynthesized(n));
let isVariableDeclarationOrBindingElement =

View file

@ -124,6 +124,19 @@ namespace ts {
}
return result;
}
export function every<T>(array: T[], f: (x: T) => boolean): boolean {
if (array) {
for (let item of array) {
if (!f(item)) {
return false;
}
return true;
}
}
return false;
}
export function map<T, U>(array: T[], f: (x: T) => U): U[]{
let result: U[];
@ -181,6 +194,28 @@ namespace ts {
}
return true;
}
/**
* Returns the first element of an array if non-empty, undefined otherwise.
*/
export function firstOrUndefined<T>(array: T[]): T {
if (array.length === 0) {
return undefined;
}
return array[0];
}
/**
* Returns the only element of an array if non-empty, undefined otherwise.
*/
export function singleOrUndefined<T>(array: T[]): T {
if (array.length === 1) {
return array[0];
}
return undefined;
}
/**
* Returns the last element of an array if non-empty, undefined otherwise.
@ -805,4 +840,4 @@ namespace ts {
Debug.assert(false, message);
}
}
}
}

View file

@ -57,7 +57,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
const awaiterHelper = `
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {
return new Promise(function (resolve, reject) {
generator = generator.call(thisArg, _arguments);
generator = generator.apply(thisArg, _arguments);
function cast(value) { return value instanceof Promise && value.constructor === Promise ? value : new Promise(function (resolve) { resolve(value); }); }
function onfulfill(value) { try { step("next", value); } catch (e) { reject(e); } }
function onreject(value) { try { step("throw", value); } catch (e) { reject(e); } }
@ -866,7 +866,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
increaseIndent();
if (nodeStartPositionsAreOnSameLine(parent, nodes[0])) {
let parentIsSynthesized = nodeIsSynthesized(parent);
if (!synthesizedNodeStartsOnNewLine(nodes[0]) && (parentIsSynthesized || nodeStartPositionsAreOnSameLine(parent, nodes[0]))) {
if (spacesBetweenBraces) {
write(" ");
}
@ -875,9 +876,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
writeLine();
}
let lastNode: Node;
for (let i = 0, n = nodes.length; i < n; i++) {
if (i) {
if (nodeEndIsOnSameLineAsNodeStart(nodes[i - 1], nodes[i])) {
if (!synthesizedNodeStartsOnNewLine(nodes[i]) && (parentIsSynthesized || nodeEndIsOnSameLineAsNodeStart(nodes[i - 1], nodes[i]))) {
write(", ");
}
else {
@ -887,6 +889,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
emit(nodes[i]);
lastNode = nodes[i];
}
if (nodes.hasTrailingComma && allowTrailingComma) {
@ -894,8 +897,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
decreaseIndent();
if (nodeEndPositionsAreOnSameLine(parent, lastOrUndefined(nodes))) {
if (!synthesizedNodeStartsOnNewLine(lastNode) && (parentIsSynthesized || nodeEndPositionsAreOnSameLine(parent, lastNode))) {
if (spacesBetweenBraces) {
write(" ");
}
@ -1120,7 +1124,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
return;
}
let emitOuterParens = isExpression(parentNode, peekNode, 1) && templateNeedsParens(node);
let emitOuterParens = isPartOfExpression(parentNode, peekNode, 1)
&& templateNeedsParens(node);
if (emitOuterParens) {
write("(");
}
@ -1520,21 +1526,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
let name = node.name;
Debug.assert(name.kind !== SyntaxKind.BindingElement);
if (name.kind === SyntaxKind.StringLiteral) {
if (isStringLiteral(name)) {
pushNode(name);
emitLiteral(<LiteralExpression>name);
emitLiteral(name);
popNode();
}
else if (name.kind === SyntaxKind.ComputedPropertyName) {
else if (isComputedPropertyName(name)) {
pushNode(name);
emitExpressionForComputedPropertyName(<ComputedPropertyName>name);
emitExpressionForComputedPropertyName(name);
popNode();
}
else {
write("\"");
if (name.kind === SyntaxKind.NumericLiteral) {
write((<LiteralExpression>name).text);
if (isNumericLiteral(name)) {
write(name.text);
}
else {
writeTextOfNode(currentSourceFile, name);
@ -1559,7 +1565,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
//
// Object.defineProperty(C.prototype, _a, __decorate([dec], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a)));
//
if (parentNode && nodeIsDecorated(parentNode)) {
if (nodeIsDecorated(parentNode)) {
if (!computedPropertyNamesToGeneratedNames) {
computedPropertyNamesToGeneratedNames = [];
}
@ -1577,7 +1583,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write(" = ");
}
emit((<ComputedPropertyName>name).expression);
emit(name.expression);
}
function isExpressionIdentifier(node: Node): boolean {
@ -1692,12 +1698,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
verifyStackBehavior(StackBehavior.NodeIsOnTopOfStack, node);
if (languageVersion < ScriptTarget.ES6) {
switch (parentNode.kind) {
let originalNode = getOriginalNode(parentNode);
switch (originalNode.kind) {
case SyntaxKind.BindingElement:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.VariableDeclaration:
return (<Declaration>parentNode).name === node && resolver.isNestedRedeclaration(<Declaration>parentNode);
return (<Declaration>originalNode).name === node && !nodeIsSynthesized(originalNode) && resolver.isNestedRedeclaration(<Declaration>originalNode);
}
}
return false;
@ -1823,10 +1830,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
function needsParenthesisForAwaitExpressionAsYield(node: AwaitExpression) {
verifyStackBehavior(StackBehavior.NodeIsOnTopOfStack, node);
if (parentNode.kind === SyntaxKind.BinaryExpression && !isAssignmentOperator((<BinaryExpression>parentNode).operatorToken.kind)) {
if (isBinaryExpression(parentNode) && !isAssignmentOperator(parentNode.operatorToken.kind)) {
return true;
}
else if (parentNode.kind === SyntaxKind.ConditionalExpression && (<ConditionalExpression>parentNode).condition === node) {
else if (isConditionalExpression(parentNode) && parentNode.condition === node) {
return true;
}
@ -2500,8 +2507,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
function emitParenExpression(node: ParenthesizedExpression) {
verifyStackBehavior(StackBehavior.NodeIsOnTopOfStack, node);
let parent = parentNode;
// If the node is synthesized, it means the emitter put the parentheses there,
// not the user. If we didn't want them, the emitter would not have put them
// there.
@ -2529,8 +2534,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
operand.kind !== SyntaxKind.DeleteExpression &&
operand.kind !== SyntaxKind.PostfixUnaryExpression &&
operand.kind !== SyntaxKind.NewExpression &&
!(operand.kind === SyntaxKind.CallExpression && parent.kind === SyntaxKind.NewExpression) &&
!(operand.kind === SyntaxKind.FunctionExpression && parent.kind === SyntaxKind.CallExpression)) {
!(operand.kind === SyntaxKind.CallExpression && parentNode.kind === SyntaxKind.NewExpression) &&
!(operand.kind === SyntaxKind.FunctionExpression && parentNode.kind === SyntaxKind.CallExpression)) {
emit(operand);
return;
}
@ -2573,15 +2578,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
return false;
}
debugger;
const parentNode = currentNode;
const isVariableDeclarationOrBindingElement =
parentNode && (parentNode.kind === SyntaxKind.VariableDeclaration || parentNode.kind === SyntaxKind.BindingElement);
currentNode && (currentNode.kind === SyntaxKind.VariableDeclaration || currentNode.kind === SyntaxKind.BindingElement);
const targetDeclaration =
isVariableDeclarationOrBindingElement
? <Declaration>parentNode
? <Declaration>currentNode
: resolver.getReferencedValueDeclaration(<Identifier>node);
return isSourceFileLevelDeclarationInSystemJsModule(targetDeclaration, /*isExported*/ true);
@ -2777,6 +2779,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
}
function isBlockWithSynthesizedStatementsOnNewLine(node: Node) {
if (isBlock(node) && forEach(node.statements, synthesizedNodeStartsOnNewLine)) {
return true;
}
return false;
}
function isSingleLineSynthesizedBlock(node: Node) {
verifyStackBehavior(StackBehavior.Unspecified, node);
if (isBlock(node) && nodeIsSynthesized(node) && node.statements.length === 1 && nodeIsSynthesized(node.statements[0])) {
return !(<SynthesizedNode>node.statements[0]).startsOnNewLine;
}
}
function emitBlock(node: Block) {
verifyStackBehavior(StackBehavior.NodeIsOnTopOfStack, node);
@ -2787,6 +2804,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
return;
}
if (isSingleLineSynthesizedBlock(node)) {
emitToken(SyntaxKind.OpenBraceToken, node.pos);
write(" ");
emit(node.statements[0]);
write(" ");
emitToken(SyntaxKind.CloseBraceToken, node.statements.end);
return;
}
emitToken(SyntaxKind.OpenBraceToken, node.pos);
increaseIndent();
scopeEmitStart(parentNode);
@ -3290,8 +3316,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
emit(node.statement);
}
function getContainingModule(node: Node): ModuleDeclaration {
do {
node = getOriginalNode(node);
node = node.parent;
} while (node && node.kind !== SyntaxKind.ModuleDeclaration);
return <ModuleDeclaration>node;
}
function isModuleDeclarationOrGeneratedNamespace(node: Node): node is ModuleDeclaration | ExpressionStatement {
return isModuleDeclaration(node) || (isExpressionStatement(node) && !!(node.flags & NodeFlags.GeneratedNamespace));
}
function emitContainingModuleName() {
let container = findAncestorNode(isModuleDeclaration);
let container = getOriginalNode(findAncestorNode(isModuleDeclarationOrGeneratedNamespace));
write(container ? getGeneratedNameForNode(container) : "exports");
}
@ -3300,7 +3338,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
emitStart(node.name);
if (getCombinedNodeFlags() & NodeFlags.Export) {
let container = findAncestorNode(isModuleDeclaration);
let container = getOriginalNode(findAncestorNode(isModuleDeclarationOrGeneratedNamespace));
if (container) {
write(getGeneratedNameForNode(container));
write(".");
@ -4005,6 +4043,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
function emitCaptureThisForNodeIfNecessary(node: Node): void {
verifyStackBehavior(StackBehavior.Unspecified);
if (compilerOptions.experimentalTransforms) {
return;
}
if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.CaptureThis) {
writeLine();
emitStart(node);
@ -4320,7 +4362,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
pushNode(body);
let preambleEmitted = writer.getTextPos() !== initialTextPos;
if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) {
if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)
&& !isBlockWithSynthesizedStatementsOnNewLine(body)
&& (!nodeIsSynthesized(body) || isSingleLineSynthesizedBlock(body))) {
for (let statement of body.statements) {
write(" ");
emit(statement);
@ -4960,6 +5004,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
function emitClassLikeDeclarationBelowES6(node: ClassLikeDeclaration) {
Debug.assert(!compilerOptions.experimentalTransforms, "This function should not be called when using '--experimentalTransforms'.");
verifyStackBehavior(StackBehavior.NodeIsOnTopOfStack, node);
if (node.kind === SyntaxKind.ClassDeclaration) {
@ -5632,6 +5677,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
function emitEnumDeclaration(node: EnumDeclaration) {
Debug.assert(!compilerOptions.experimentalTransforms, "This function should not be called when using '--experimentalTransforms'.");
verifyStackBehavior(StackBehavior.NodeIsOnTopOfStack, node);
// const enums are completely erased during compilation.
@ -5753,6 +5799,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
function emitModuleDeclaration(node: ModuleDeclaration) {
Debug.assert(!compilerOptions.experimentalTransforms, "This function should not be called when using '--experimentalTransforms'.");
verifyStackBehavior(StackBehavior.NodeIsOnTopOfStack, node);
// Emit only if this module is non-ambient.
@ -7222,7 +7270,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
// Process tree transformations
let statements = node.statements;
if (compilerOptions.experimentalTransforms) {
if (compilerOptions.experimentalTransforms || true) {
let context = new transform.VisitorContext(compilerOptions, currentSourceFile, resolver, generatedNameSet, nodeToGeneratedName);
statements = transformationChain(context, node.statements);
}
@ -7290,25 +7338,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
popNode();
}
function emitWithStackBehavior<T extends Node, U>(node: T, emit: (node: T) => U, stackBehavior: StackBehavior): U {
let result: U;
if (stackBehavior === StackBehavior.NodeIsOnTopOfStack && currentNode !== node) {
pushNode(node);
result = emit(node);
popNode();
}
else if (stackBehavior === StackBehavior.ParentIsOnTopOfStack && currentNode === node) {
popNode();
result = emit(node);
pushNode(node);
}
else {
result = emit(node);
}
return result;
}
function emitNodeWithoutSourceMap(node: Node): void {
if (!node) {
return;
@ -7601,11 +7630,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
function getLeadingCommentsToEmit(node: Node) {
verifyStackBehavior(StackBehavior.NodeIsOnTopOfStack, node);
if ((<SynthesizedNode>node).leadingCommentRanges) {
if (nodeIsSynthesized(node)) {
return (<SynthesizedNode>node).leadingCommentRanges;
}
node = getOriginalNode(node);
//node = getOriginalNode(node);
// Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments
if (parentNode) {
@ -7625,11 +7654,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
function getTrailingCommentsToEmit(node: Node) {
verifyStackBehavior(StackBehavior.NodeIsOnTopOfStack, node);
if ((<SynthesizedNode>node).trailingCommentRanges) {
if (nodeIsSynthesized(node)) {
return (<SynthesizedNode>node).trailingCommentRanges;
}
node = getOriginalNode(node);
//node = getOriginalNode(node);
// Emit the trailing comments only if the parent's pos doesn't match because parent should take care of emitting these comments
if (parentNode && !nodeIsSynthesized(parentNode)) {
if (parentNode.kind === SyntaxKind.SourceFile || node.end !== parentNode.end) {

View file

@ -46,8 +46,17 @@ namespace ts {
}
return node;
}
export function createThisKeyword(location?: TextRange, flags?: NodeFlags): LeftHandSideExpression {
return createNode<LeftHandSideExpression>(SyntaxKind.ThisKeyword, location, flags);
export function createFalseKeyword(location?: TextRange, flags?: NodeFlags): PrimaryExpression {
return createNode<PrimaryExpression>(SyntaxKind.FalseKeyword, location, flags);
}
export function createSuperKeyword(location?: TextRange, flags?: NodeFlags): PrimaryExpression {
return createNode<PrimaryExpression>(SyntaxKind.SuperKeyword, location, flags);
}
export function createThisKeyword(location?: TextRange, flags?: NodeFlags): PrimaryExpression {
return createNode<PrimaryExpression>(SyntaxKind.ThisKeyword, location, flags);
}
export function createTrueKeyword(location?: TextRange, flags?: NodeFlags): PrimaryExpression {
return createNode<PrimaryExpression>(SyntaxKind.TrueKeyword, location, flags);
}
export function createQualifiedName(left?: EntityName, right?: Identifier, location?: TextRange, flags?: NodeFlags): QualifiedName {
let node = createNode<QualifiedName>(SyntaxKind.QualifiedName, location, flags);
@ -110,10 +119,10 @@ namespace ts {
return node;
}
export function updateParameter(node: ParameterDeclaration, decorators: Array<Decorator>, modifiers: Array<Node>
, 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);
, name: BindingPattern | Identifier, questionToken: Node, type: TypeNode, initializer: Expression): ParameterDeclaration {
if (decorators !== node.decorators || modifiers !== node.modifiers || name !== node.name || questionToken !== node.questionToken ||
type !== node.type || initializer !== node.initializer) {
let newNode = createParameter(decorators, modifiers, node.dotDotDotToken, name, questionToken, type, initializer);
return updateFrom(node, newNode);
}
return node;
@ -994,15 +1003,20 @@ namespace ts {
}
return node;
}
export function createVariableStatement(declarationList?: VariableDeclarationList,
export function createVariableStatement(decorators?: Array<Decorator>, modifiers?: Array<Node>, declarationList?: VariableDeclarationList,
location?: TextRange, flags?: NodeFlags): VariableStatement {
let node = createNode<VariableStatement>(SyntaxKind.VariableStatement, location, flags);
node.declarationList = declarationList;
if (arguments.length) {
node.decorators = decorators && createNodeArray(decorators)
setModifiers(node, modifiers);
node.declarationList = declarationList;
}
return node;
}
export function updateVariableStatement(node: VariableStatement, declarationList: VariableDeclarationList): VariableStatement {
if (declarationList !== node.declarationList) {
let newNode = createVariableStatement(declarationList);
export function updateVariableStatement(node: VariableStatement, decorators: Array<Decorator>, modifiers: Array<Node>
, declarationList: VariableDeclarationList): VariableStatement {
if (decorators !== node.decorators || modifiers !== node.modifiers || declarationList !== node.declarationList) {
let newNode = createVariableStatement(decorators, modifiers, declarationList);
return updateFrom(node, newNode);
}
return node;
@ -1242,23 +1256,20 @@ namespace ts {
export function createDebuggerStatement(location?: TextRange, flags?: NodeFlags): DebuggerStatement {
return createNode<DebuggerStatement>(SyntaxKind.DebuggerStatement, location, flags);
}
export function createVariableDeclaration(decorators?: Array<Decorator>, modifiers?: Array<Node>, name?: BindingPattern | Identifier,
type?: TypeNode, initializer?: Expression, location?: TextRange, flags?: NodeFlags): VariableDeclaration {
export function createVariableDeclaration(name?: BindingPattern | Identifier, type?: TypeNode, initializer?: Expression,
location?: TextRange, flags?: NodeFlags): VariableDeclaration {
let node = createNode<VariableDeclaration>(SyntaxKind.VariableDeclaration, location, flags);
if (arguments.length) {
node.decorators = decorators && createNodeArray(decorators)
setModifiers(node, modifiers);
node.name = name;
node.type = type;
node.initializer = initializer;
}
return node;
}
export function updateVariableDeclaration(node: VariableDeclaration, decorators: Array<Decorator>, modifiers: Array<Node>
, 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);
export function updateVariableDeclaration(node: VariableDeclaration, name: BindingPattern | Identifier, type: TypeNode
, initializer: Expression): VariableDeclaration {
if (name !== node.name || type !== node.type || initializer !== node.initializer) {
let newNode = createVariableDeclaration(name, type, initializer);
return updateFrom(node, newNode);
}
return node;
@ -1759,14 +1770,18 @@ namespace ts {
}
return node;
}
export function createHeritageClause(types?: Array<ExpressionWithTypeArguments>, location?: TextRange, flags?: NodeFlags): HeritageClause {
export function createHeritageClause(token?: SyntaxKind, types?: Array<ExpressionWithTypeArguments>,
location?: TextRange, flags?: NodeFlags): HeritageClause {
let node = createNode<HeritageClause>(SyntaxKind.HeritageClause, location, flags);
node.types = types && createNodeArray(types)
if (arguments.length) {
node.token = token;
node.types = types && createNodeArray(types)
}
return node;
}
export function updateHeritageClause(node: HeritageClause, types: Array<ExpressionWithTypeArguments>): HeritageClause {
if (types !== node.types) {
let newNode = createHeritageClause(types);
let newNode = createHeritageClause(node.token, types);
return updateFrom(node, newNode);
}
return node;
@ -1787,35 +1802,30 @@ namespace ts {
}
return node;
}
export function createPropertyAssignment(name?: PropertyName, questionToken?: Node, initializer?: Expression,
export function createPropertyAssignment(name?: PropertyName, initializer?: Expression,
location?: TextRange, flags?: NodeFlags): PropertyAssignment {
let node = createNode<PropertyAssignment>(SyntaxKind.PropertyAssignment, location, flags);
if (arguments.length) {
node.name = name;
node.questionToken = questionToken;
node.initializer = initializer;
}
return node;
}
export function updatePropertyAssignment(node: PropertyAssignment, name: PropertyName, initializer: Expression): PropertyAssignment {
if (name !== node.name || initializer !== node.initializer) {
let newNode = createPropertyAssignment(name, node.questionToken, initializer);
let newNode = createPropertyAssignment(name, initializer);
return updateFrom(node, newNode);
}
return node;
}
export function createShorthandPropertyAssignment(name?: Identifier, questionToken?: Node,
location?: TextRange, flags?: NodeFlags): ShorthandPropertyAssignment {
export function createShorthandPropertyAssignment(name?: Identifier, location?: TextRange, flags?: NodeFlags): ShorthandPropertyAssignment {
let node = createNode<ShorthandPropertyAssignment>(SyntaxKind.ShorthandPropertyAssignment, location, flags);
if (arguments.length) {
node.name = name;
node.questionToken = questionToken;
}
node.name = name;
return node;
}
export function updateShorthandPropertyAssignment(node: ShorthandPropertyAssignment, name: Identifier): ShorthandPropertyAssignment {
if (name !== node.name) {
let newNode = createShorthandPropertyAssignment(name, node.questionToken);
let newNode = createShorthandPropertyAssignment(name);
return updateFrom(node, newNode);
}
return node;
@ -2144,8 +2154,14 @@ namespace ts {
return factory.createTemplateTail((<LiteralExpression>node).text, location, flags);
case SyntaxKind.Identifier:
return factory.createIdentifier((<Identifier>node).text, (<Identifier>node).originalKeywordKind, location, flags);
case SyntaxKind.FalseKeyword:
return factory.createFalseKeyword(location, flags);
case SyntaxKind.SuperKeyword:
return factory.createSuperKeyword(location, flags);
case SyntaxKind.ThisKeyword:
return factory.createThisKeyword(location, flags);
case SyntaxKind.TrueKeyword:
return factory.createTrueKeyword(location, flags);
case SyntaxKind.QualifiedName:
return factory.createQualifiedName((<QualifiedName>node).left, (<QualifiedName>node).right, location, flags);
case SyntaxKind.ComputedPropertyName:
@ -2307,7 +2323,8 @@ namespace ts {
case SyntaxKind.Block:
return factory.createBlock((<Block>node).statements, location, flags);
case SyntaxKind.VariableStatement:
return factory.createVariableStatement((<VariableStatement>node).declarationList, location, flags);
return factory.createVariableStatement((<VariableStatement>node).decorators, (<VariableStatement>node).modifiers,
(<VariableStatement>node).declarationList, location, flags);
case SyntaxKind.EmptyStatement:
return factory.createEmptyStatement(location, flags);
case SyntaxKind.ExpressionStatement:
@ -2348,9 +2365,8 @@ namespace ts {
case SyntaxKind.DebuggerStatement:
return factory.createDebuggerStatement(location, flags);
case SyntaxKind.VariableDeclaration:
return factory.createVariableDeclaration((<VariableDeclaration>node).decorators, (<VariableDeclaration>node).modifiers,
(<VariableDeclaration>node).name, (<VariableDeclaration>node).type, (<VariableDeclaration>node).initializer,
location, flags);
return factory.createVariableDeclaration((<VariableDeclaration>node).name, (<VariableDeclaration>node).type,
(<VariableDeclaration>node).initializer, location, flags);
case SyntaxKind.VariableDeclarationList:
return factory.createVariableDeclarationList((<VariableDeclarationList>node).declarations, location, flags);
case SyntaxKind.FunctionDeclaration:
@ -2432,15 +2448,14 @@ namespace ts {
case SyntaxKind.DefaultClause:
return factory.createDefaultClause((<DefaultClause>node).statements, location, flags);
case SyntaxKind.HeritageClause:
return factory.createHeritageClause((<HeritageClause>node).types, location, flags);
return factory.createHeritageClause((<HeritageClause>node).token, (<HeritageClause>node).types, location, flags);
case SyntaxKind.CatchClause:
return factory.createCatchClause((<CatchClause>node).variableDeclaration, (<CatchClause>node).block, location, flags);
case SyntaxKind.PropertyAssignment:
return factory.createPropertyAssignment((<PropertyAssignment>node).name, (<PropertyAssignment>node).questionToken,
(<PropertyAssignment>node).initializer, location, flags);
return factory.createPropertyAssignment((<PropertyAssignment>node).name, (<PropertyAssignment>node).initializer,
location, flags);
case SyntaxKind.ShorthandPropertyAssignment:
return factory.createShorthandPropertyAssignment((<ShorthandPropertyAssignment>node).name,
(<ShorthandPropertyAssignment>node).questionToken, location, flags);
return factory.createShorthandPropertyAssignment((<ShorthandPropertyAssignment>node).name, location, flags);
case SyntaxKind.EnumMember:
return factory.createEnumMember((<EnumMember>node).name, (<EnumMember>node).initializer, location, flags);
case SyntaxKind.JSDocTypeExpression:
@ -2520,19 +2535,19 @@ namespace ts {
export function isIdentifier(node: Node): node is Identifier {
return node && node.kind === SyntaxKind.Identifier;
}
export function isFalseKeyword(node: Node): node is LeftHandSideExpression {
export function isFalseKeyword(node: Node): node is PrimaryExpression {
return node && node.kind === SyntaxKind.FalseKeyword;
}
export function isNullKeyword(node: Node): node is LeftHandSideExpression {
export function isNullKeyword(node: Node): node is PrimaryExpression {
return node && node.kind === SyntaxKind.NullKeyword;
}
export function isSuperKeyword(node: Node): node is LeftHandSideExpression {
export function isSuperKeyword(node: Node): node is PrimaryExpression {
return node && node.kind === SyntaxKind.SuperKeyword;
}
export function isThisKeyword(node: Node): node is LeftHandSideExpression {
export function isThisKeyword(node: Node): node is PrimaryExpression {
return node && node.kind === SyntaxKind.ThisKeyword;
}
export function isTrueKeyword(node: Node): node is LeftHandSideExpression {
export function isTrueKeyword(node: Node): node is PrimaryExpression {
return node && node.kind === SyntaxKind.TrueKeyword;
}
export function isQualifiedName(node: Node): node is QualifiedName {
@ -2950,6 +2965,56 @@ namespace ts {
}
return false;
}
export function isExpression(node: Node): node is Expression {
if (node) {
switch (node.kind) {
case SyntaxKind.OmittedExpression:
case SyntaxKind.Identifier:
case SyntaxKind.TrueKeyword:
case SyntaxKind.FalseKeyword:
case SyntaxKind.NullKeyword:
case SyntaxKind.ThisKeyword:
case SyntaxKind.SuperKeyword:
case SyntaxKind.NumericLiteral:
case SyntaxKind.RegularExpressionLiteral:
case SyntaxKind.NoSubstitutionTemplateLiteral:
case SyntaxKind.TemplateHead:
case SyntaxKind.TemplateMiddle:
case SyntaxKind.TemplateTail:
case SyntaxKind.StringLiteral:
case SyntaxKind.PrefixUnaryExpression:
case SyntaxKind.PostfixUnaryExpression:
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.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.JsxExpression:
case SyntaxKind.JsxSelfClosingElement:
case SyntaxKind.ClassExpression:
return true;
}
}
return false;
}
export function isBindingPatternOrIdentifier(node: Node): node is BindingPattern | Identifier {
if (node) {
switch (node.kind) {

View file

@ -42,8 +42,13 @@ namespace ts {
}
export function attachCommentRanges<T extends Node>(node: T, leadingCommentRanges: CommentRange[], trailingCommentRanges?: CommentRange[]): T {
(<SynthesizedNode><Node>node).leadingCommentRanges = leadingCommentRanges;
(<SynthesizedNode><Node>node).trailingCommentRanges = trailingCommentRanges;
(<SynthesizedNode>node).leadingCommentRanges = leadingCommentRanges;
(<SynthesizedNode>node).trailingCommentRanges = trailingCommentRanges;
return node;
}
export function startOnNewLine<T extends Node>(node: T): T {
(<SynthesizedNode>node).startsOnNewLine = true;
return node;
}
@ -73,6 +78,10 @@ namespace ts {
}
}
export function cloneNodeArray<T extends Node>(array: NodeArray<T>): NodeArray<T> {
return array ? factory.createNodeArray(array.slice(0), /*location*/ array) : undefined;
}
export function createNode<T extends Node>(kind: SyntaxKind, location?: TextRange, flags?: NodeFlags): T {
return setNodeFlags(setTextRange(<T>new (getNodeConstructor(kind))(), location), flags);
}
@ -120,6 +129,35 @@ namespace ts {
flags
);
}
export const enum BinaryOperand {
Left,
Right
}
export function parenthesizeForBinary(expr: Expression, operator: SyntaxKind) {
// When diagnosing whether the expression needs parentheses, the decision should be based
// on the innermost expression in a chain of nested type assertions.
while (expr.kind === SyntaxKind.TypeAssertionExpression || expr.kind === SyntaxKind.AsExpression) {
expr = (<AssertionExpression>expr).expression;
}
// If the resulting expression is already parenthesized, we do not need to do any further processing.
if (isParenthesizedExpression(expr)) {
return expr;
}
let exprPrecedence = getExpressionPrecedence(expr);
let operatorPrecedence = getBinaryOperatorPrecedence(operator);
if (exprPrecedence < operatorPrecedence) {
// lower precedence, the expression needs parenthesis
return factory.createParenthesizedExpression(expr);
}
else {
// higher precedence.
return expr;
}
}
export function parenthesizeForAccess(expr: Expression): LeftHandSideExpression {
// When diagnosing whether the expression needs parentheses, the decision should be based
@ -146,9 +184,9 @@ namespace ts {
return factory.createParenthesizedExpression(expr);
}
export function createCallExpression2(expression: LeftHandSideExpression, _arguments?: Expression[], location?: TextRange, flags?: NodeFlags) {
export function createCallExpression2(expression: Expression, _arguments?: Expression[], location?: TextRange, flags?: NodeFlags) {
return factory.createCallExpression(
expression,
parenthesizeForAccess(expression),
/*typeArguments*/ undefined,
_arguments,
location,
@ -156,21 +194,43 @@ namespace ts {
);
}
export function createAssignmentExpression(left: Expression, right: Expression, location?: TextRange, flags?: NodeFlags) {
return factory.createBinaryExpression2(left, SyntaxKind.EqualsToken, right, location, flags);
export function createObjectLiteralExpression2(properties?: ObjectLiteralElement[]) {
return createObjectLiteralExpression(
/*decorators*/ undefined,
/*modifiers*/ undefined,
createNodeArray(properties)
);
}
export function createAssignmentExpressionStatement(left: Expression, right: Expression, location?: TextRange, flags?: NodeFlags) {
return factory.createExpressionStatement(factory.createAssignmentExpression(left, right), location, flags);
export function createAssignmentExpression(left: Expression, right: Expression) {
return createBinaryExpression2(left, SyntaxKind.EqualsToken, right);
}
export function createStrictEqualityExpression(left: Expression, right: Expression) {
return createBinaryExpression2(left, SyntaxKind.EqualsEqualsEqualsToken, right);
}
export function createStrictInequalityExpression(left: Expression, right: Expression) {
return createBinaryExpression2(left, SyntaxKind.ExclamationEqualsEqualsToken, right);
}
export function createLogicalAndExpression(left: Expression, right: Expression) {
return createBinaryExpression2(left, SyntaxKind.AmpersandAmpersandToken, right);
}
export function createLogicalOrExpression(left: Expression, right: Expression) {
return createBinaryExpression2(left, SyntaxKind.BarBarToken, right);
}
export function createCommaExpression(left: Expression, right: Expression) {
return createBinaryExpression2(left, SyntaxKind.CommaToken, right);
}
export function createBinaryExpression2(left: Expression, operator: SyntaxKind, right: Expression, location?: TextRange, flags?: NodeFlags) {
export function createBinaryExpression2(left: Expression, operator: SyntaxKind, right: Expression) {
return factory.createBinaryExpression(
left,
parenthesizeForBinary(left, operator),
factory.createNode(operator),
right,
location,
flags
parenthesizeForBinary(right, operator)
);
}
@ -186,21 +246,7 @@ namespace ts {
);
}
export function createInlineFunctionExpressionEvaluation(parameters: ParameterDeclaration[], bodyStatements: Statement[], _arguments: Expression[], location?: TextRange, flags?: NodeFlags) {
return factory.createCallExpression2(
factory.createParenthesizedExpression(
factory.createFunctionExpression5(
parameters,
bodyStatements
)
),
_arguments,
location,
flags
);
}
export function createParameter2(name: BindingPattern | Identifier, location?: TextRange, flags?: NodeFlags) {
export function createParameter2(name: BindingPattern | Identifier, initializer?: Expression, location?: TextRange, flags?: NodeFlags) {
return factory.createParameter(
/*decorators*/ undefined,
/*modifiers*/ undefined,
@ -208,7 +254,7 @@ namespace ts {
name,
/*questionToken*/ undefined,
/*type*/ undefined,
/*initializer*/ undefined,
initializer,
location,
flags
);
@ -228,20 +274,18 @@ namespace ts {
);
}
export function createVariableStatement2(name: Identifier, initializer?: Expression, location?: TextRange, flags?: NodeFlags) {
export function createVariableStatement2(declarationList: VariableDeclarationList, location?: TextRange, flags?: NodeFlags) {
return factory.createVariableStatement(
factory.createVariableDeclarationList([
factory.createVariableDeclaration2(name, initializer)
], /*location*/ undefined, flags & (NodeFlags.Let | NodeFlags.Const)),
/*decorators*/ undefined,
/*modifiers*/ undefined,
declarationList,
location,
flags & ~(NodeFlags.Let | NodeFlags.Const)
flags
);
}
export function createVariableDeclaration2(name: Identifier, initializer?: Expression, location?: TextRange, flags?: NodeFlags) {
export function createVariableDeclaration2(name: Identifier | BindingPattern, initializer?: Expression, location?: TextRange, flags?: NodeFlags) {
return factory.createVariableDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,
name,
/*type*/ undefined,
initializer,
@ -250,14 +294,16 @@ namespace ts {
);
}
export function createClassDeclaration2(modifiers: Modifier[], name: Identifier, heritageClause: HeritageClause, members: ClassElement[]): ClassDeclaration {
export function createClassDeclaration2(name: Identifier, heritageClause: HeritageClause, members: ClassElement[], location?: TextRange, flags?: NodeFlags): ClassDeclaration {
return factory.createClassDeclaration(
/*decorators*/ undefined,
modifiers,
/*modifiers*/ undefined,
name,
/*typeParameters*/ undefined,
heritageClause ? [heritageClause] : undefined,
members
members,
location,
flags
);
}
@ -272,11 +318,56 @@ namespace ts {
);
}
export function createClassExpression3(heritageClause: HeritageClause, members: ClassElement[]) {
return factory.createClassExpression2(
/*name*/ undefined,
heritageClause,
members
export function createConstructor2(parameters: Array<ParameterDeclaration>, body: Block, location?: TextRange, flags?: NodeFlags): ConstructorDeclaration {
return factory.createConstructor(
/*decorators*/ undefined,
/*modifiers*/ undefined,
parameters,
/*type*/ undefined,
body,
location,
flags
);
}
export function createMethodDeclaration2(name: PropertyName, parameters: Array<ParameterDeclaration>, body: Block, location?: TextRange, flags?: NodeFlags): MethodDeclaration {
return factory.createMethodDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,
/*asteriskToken*/ undefined,
name,
/*typeParameters*/ undefined,
parameters,
/*type*/ undefined,
body,
location,
flags
);
}
export function createGetAccessor2(name: PropertyName, parameters: Array<ParameterDeclaration>, body: Block, location?: TextRange, flags?: NodeFlags): GetAccessorDeclaration {
return factory.createGetAccessor(
/*decorators*/ undefined,
/*modifiers*/ undefined,
name,
parameters,
/*type*/ undefined,
body,
location,
flags
);
}
export function createSetAccessor2(name: PropertyName, parameters: Array<ParameterDeclaration>, body: Block, location?: TextRange, flags?: NodeFlags): SetAccessorDeclaration {
return factory.createSetAccessor(
/*decorators*/ undefined,
/*modifiers*/ undefined,
name,
parameters,
/*type*/ undefined,
body,
location,
flags
);
}
@ -294,22 +385,28 @@ namespace ts {
flags
);
}
export function createFunctionDeclaration3(name: Identifier, parameters: ParameterDeclaration[], body: Statement[], location?: TextRange, flags?: NodeFlags) {
return factory.createFunctionDeclaration2(
export function createFunctionDeclaration3(asteriskToken: Node, name: Identifier, parameters: ParameterDeclaration[], body: Block, location?: TextRange, flags?: NodeFlags) {
return factory.createFunctionDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,
asteriskToken,
name,
/*typeParameters*/ undefined,
parameters,
factory.createBlock(body || []),
/*type*/ undefined,
body,
location,
flags);
}
flags
);
}
export function createFunctionExpression2(name: Identifier, parameters: ParameterDeclaration[], body: Block, location?: TextRange, flags?: NodeFlags) {
return factory.createFunctionExpression(
/*decorators*/ undefined,
/*modifiers*/ undefined,
/*asteriskToken*/ undefined,
/*name*/ undefined,
name,
/*typeParameters*/ undefined,
parameters,
/*type*/ undefined,
@ -319,31 +416,31 @@ namespace ts {
);
}
export function createFunctionExpression3(parameters: ParameterDeclaration[], body: Block, location?: TextRange, flags?: NodeFlags) {
return factory.createFunctionExpression2(
/*name*/ undefined,
export function createFunctionExpression3(asteriskToken: Node, name: Identifier, parameters: ParameterDeclaration[], body: Block, location?: TextRange, flags?: NodeFlags) {
return factory.createFunctionExpression(
/*decorators*/ undefined,
/*modifiers*/ undefined,
asteriskToken,
name,
/*typeParameters*/ undefined,
parameters,
/*type*/ undefined,
body,
location,
flags
);
}
export function createFunctionExpression4(name: Identifier, parameters: ParameterDeclaration[], body: Statement[], location?: TextRange, flags?: NodeFlags) {
return factory.createFunctionExpression2(
export function createGeneratorFunctionExpression(name: Identifier, parameters: ParameterDeclaration[], body: Block, location?: TextRange, flags?: NodeFlags) {
return factory.createFunctionExpression(
/*decorators*/ undefined,
/*modifiers*/ undefined,
createNode(SyntaxKind.AsteriskToken),
name,
/*typeParameters*/ undefined,
parameters,
factory.createBlock(body || []),
location,
flags
);
}
export function createFunctionExpression5(parameters: ParameterDeclaration[], body: Statement[], location?: TextRange, flags?: NodeFlags) {
return factory.createFunctionExpression2(
/*name*/ undefined,
parameters,
factory.createBlock(body || []),
/*type*/ undefined,
body,
location,
flags
);
@ -398,15 +495,96 @@ namespace ts {
);
}
export function createApplyCall(target: Expression, thisArg: Expression, _arguments: Expression, location?: TextRange, flags?: NodeFlags) {
let applyName = createIdentifier("apply");
let propExpr = createPropertyAccessExpression2(target, applyName);
return factory.createCallExpression2(propExpr, [thisArg, _arguments], location, flags);
}
export function createExtendsHelperCall(name: Identifier) {
let extendsName = factory.createIdentifier("__extends");
let superName = factory.createIdentifier("_super");
let callExpr = factory.createCallExpression2(extendsName, [name, superName]);
return callExpr;
}
export function createAwaiterHelperCall(hasLexicalArguments: boolean, promiseConstructor: EntityName | Expression, body: Block) {
let thisExpr = factory.createThisKeyword();
let awaiterName = factory.createIdentifier("__awaiter");
let argumentsExpr = hasLexicalArguments ? factory.createIdentifier("arguments") : factory.createVoidZeroExpression();
let promiseExpr = promiseConstructor ? convertEntityNameToExpression(promiseConstructor) : factory.createIdentifier("Promise");
let generatorFunc = factory.createGeneratorFunctionExpression(/*name*/ undefined, [], body);
let callExpr = factory.createCallExpression2(awaiterName, [thisExpr, argumentsExpr, promiseExpr, generatorFunc]);
return callExpr;
}
function convertEntityNameToExpression(node: EntityName | Expression): Expression {
if (isQualifiedName(node)) {
let left = convertEntityNameToExpression(node.left);
let right = factory.cloneNode(node.right);
return factory.createPropertyAccessExpression2(left, right);
}
else {
return factory.cloneNode(node);
}
}
export function createDecorateHelperCall(decoratorExpressions: Expression[], target: Expression, memberName?: Expression, descriptor?: Expression) {
let _arguments: Expression[] = [
factory.createArrayLiteralExpression(decoratorExpressions),
target
];
if (memberName) {
_arguments.push(memberName);
if (descriptor) {
_arguments.push(descriptor);
}
}
let decorateHelperName = factory.createIdentifier("__decorate");
let decoratorsExpr = factory.createArrayLiteralExpression(decoratorExpressions);
let callExpr = factory.createCallExpression2(decorateHelperName, _arguments);
return callExpr;
}
export function createParamHelperCall(parameterIndex: number, decoratorExpression: Expression) {
let paramHelperName = factory.createIdentifier("__param");
let parameterIndexExpr = factory.createNumericLiteral(String(parameterIndex));
let callExpr = factory.createCallExpression2(paramHelperName, [parameterIndexExpr, decoratorExpression]);
return callExpr;
}
export function createMetadataHelperCall(metadataKey: string, metadataValue: Expression) {
let metadataHelperName = factory.createIdentifier("__metadata");
let metadataKeyExpr = factory.createStringLiteral(metadataKey);
let callExpr = factory.createCallExpression2(metadataHelperName, [metadataKeyExpr, metadataValue]);
return callExpr;
}
export function createDefinePropertyCall(target: Expression, memberName: Expression, descriptor: Expression) {
let globalObjectName = factory.createIdentifier("Object");
let definePropertyName = factory.createIdentifier("defineProperty");
let propExpr = factory.createPropertyAccessExpression(globalObjectName, factory.createNode(SyntaxKind.DotToken), definePropertyName);
let callExpr = factory.createCallExpression2(propExpr, [target, memberName, descriptor]);
return callExpr;
}
export function createGetOwnPropertyDescriptorCall(target: Expression, memberName: Expression) {
let globalObjectName = factory.createIdentifier("Object");
let getOwnPropertyDescriptorName = factory.createIdentifier("getOwnPropertyDescriptor");
let propExpr = factory.createPropertyAccessExpression(globalObjectName, factory.createNode(SyntaxKind.DotToken), getOwnPropertyDescriptorName);
let callExpr = factory.createCallExpression2(propExpr, [target, memberName]);
return callExpr;
}
export function createDefaultValueCheck(value: Expression, defaultValue: Expression, ensureIdentifier: (value: Expression) => Expression, location?: TextRange, flags?: NodeFlags): Expression {
// The value expression will be evaluated twice, so for anything but a simple identifier
// we need to generate a temporary variable
value = ensureIdentifier(value);
// <value> === void 0 ? <defaultValue> : <value>
return factory.createConditionalExpression2(factory.createAssignmentExpression(value, factory.createVoidZeroExpression()), defaultValue, value, location, flags);
return factory.createConditionalExpression2(factory.createStrictEqualityExpression(value, factory.createVoidZeroExpression()), defaultValue, value, location, flags);
}
export function createMemberAccessForPropertyName(target: Expression, memberName: DeclarationName, location?: TextRange, flags?: NodeFlags): MemberExpression {
if (isStringLiteral(memberName) || isNumericLiteral(memberName)) {
return factory.createElementAccessExpression2(
@ -438,7 +616,7 @@ namespace ts {
export function inlineExpressions(expressions: Expression[]) {
let expression = expressions[0];
for (let i = 1; i < expressions.length; i++) {
expression = factory.createBinaryExpression2(
expression = createBinaryExpression2(
expression,
SyntaxKind.CommaToken,
expressions[i]

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -2,6 +2,7 @@
/// <reference path="../transform.ts" />
/// <reference path="es6.ts" />
/// <reference path="es5.ts" />
/*@internal*/
namespace ts.transform {
export type TransformationChain = (context: VisitorContext, statements: NodeArray<Statement>) => NodeArray<Statement>;
@ -23,26 +24,39 @@ namespace ts.transform {
}
}
function runTransformation(chain: TransformationChain, context: VisitorContext, statements: NodeArray<Statement>) {
context.pushLexicalEnvironment();
let transformed = chain(context, statements);
if (context.hasHoistedDeclarations()) {
transformed = factory.cloneNodeArray(transformed);
context.writeHoistedDeclarations(transformed);
}
context.popLexicalEnvironment();
return transformed;
}
function createUnaryTransformationChain(only: TransformationChain) {
return function (context: VisitorContext, statements: NodeArray<Statement>) {
if (only) statements = only(context, statements);
if (only) statements = runTransformation(only, context, statements);
return statements;
};
}
function createBinaryTransformationChain(first: TransformationChain, second: TransformationChain) {
return function (context: VisitorContext, statements: NodeArray<Statement>) {
if (first) statements = first(context, statements);
if (second) statements = second(context, statements);
if (first) statements = runTransformation(first, context, statements);
if (second) statements = runTransformation(second, context, statements);
return statements;
};
}
function createTrinaryTransformationChain(first: TransformationChain, second: TransformationChain, third: TransformationChain) {
return function (context: VisitorContext, statements: NodeArray<Statement>) {
if (first) statements = first(context, statements);
if (second) statements = second(context, statements);
if (third) statements = third(context, statements);
if (first) statements = runTransformation(first, context, statements);
if (second) statements = runTransformation(second, context, statements);
if (third) statements = runTransformation(third, context, statements);
return statements;
};
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -488,6 +488,14 @@ namespace ts {
return Array(paddingLength + 1).join(" ");
}
}
declare var global: any, require: any;
if (typeof global !== "undefined" && Object.prototype.toString.call(global.process) === '[object process]') {
try {
require("source-map-support").install();
}
catch (e) { }
}
}
ts.executeCommandLine(ts.sys.args);

View file

@ -337,7 +337,7 @@ namespace ts {
LastKeyword = OfKeyword,
FirstFutureReservedWord = ImplementsKeyword,
LastFutureReservedWord = YieldKeyword,
FirstTypeNode = TypeReference,
FirstTypeNode = TypePredicate,
LastTypeNode = ParenthesizedType,
FirstPunctuation = OpenBraceToken,
LastPunctuation = CaretEqualsToken,
@ -372,6 +372,9 @@ namespace ts {
OctalLiteral = 0x00010000, // Octal numeric literal
Namespace = 0x00020000, // Namespace declaration
ExportContext = 0x00040000, // Export context (initialized by binding)
GeneratedRest = 0x00080000, // Synthetic node generated during transformation
GeneratedSuper = 0x00100000, // Synthetic node generated during transformation
GeneratedNamespace =0x00200000, // Synthetic node generated during transformation
Modifier = Export | Ambient | Public | Private | Protected | Static | Abstract | Default | Async,
AccessibilityModifier = Public | Private | Protected,
@ -433,56 +436,51 @@ namespace ts {
ContainsTypeScript = 1 << 2,
ContainsTypeScriptPropertyDeclarationWithInitializer = 1 << 3,
ContainsTypeScriptClassSyntaxExtension = 1 << 4,
ContainsTypeScriptGeneratedStatements = 1 << 5,
ContainsTypeScriptDecorator = 1 << 6,
// A fact that states that a node is ES6 syntax
ES6 = 1 << 6,
ES6 = 1 << 7,
// A fact that states that this node or its subtree contains ES6 syntax
ContainsES6 = 1 << 7,
ContainsES6 = 1 << 8,
ContainsES6Yield = 1 << 8,
ContainsES6Yield = 1 << 9,
// A fact that states that this node or its subtree contains an ES6 Binding Pattern
ContainsES6BindingPattern = 1 << 9,
ContainsES6ParameterBindingPattern = 1 << 10,
ContainsES6VariableBindingPattern = 1 << 11,
// A fact that states that this node or its subtree contains an ES6 Rest Parameter
ContainsES6RestParameter = 1 << 10,
ContainsES6RestParameter = 1 << 12,
// A fact that states that this node or its subtree contains an ES6 Parameter Initializer
ContainsES6ParameterInitializer = 1 << 11,
ContainsES6ParameterInitializer = 1 << 13,
ContainsES6SpreadElement = 1 << 12,
ContainsES6SpreadElement = 1 << 14,
ContainsES6LetOrConst = 1 << 13,
ContainsES6LetOrConst = 1 << 15,
ContainsES6ComputedPropertyName = 1 << 16,
// A fact that states that this node or its subtree contains a captured lexical `this` binding
ContainsCapturedThis = 1 << 14,
ContainsCapturedThis = 1 << 17,
// A fact that states that this node or its subtree contains a lexical `this` binding
ContainsLexicalThis = 1 << 15,
ContainsLexicalThis = 1 << 18,
ContainsHoistedDeclarationInES6Generator = 1 << 16,
ContainsCompletionStatementInES6Genertator = 1 << 17,
ContainsHoistedDeclaration = 1 << 19,
ContainsCompletionStatement = 1 << 20,
// Template Transform Facts
ContainsTemplatePlaceholder = 1 << 21,
//
// Assertions
//
ThisNodeIsTypeScript = TypeScript | ContainsTypeScript,
ThisNodeIsTypeScriptAccessibilityModifier = ThisNodeIsTypeScript,
ThisNodeIsTypeScriptOverload = ThisNodeIsTypeScript,
ThisNodeIsTypeScriptPropertyDeclaration = ThisNodeIsTypeScript | ContainsTypeScriptClassSyntaxExtension,
ThisNodeIsTypeScriptPropertyDeclarationWithInitializer = ThisNodeIsTypeScriptPropertyDeclaration | ContainsTypeScriptPropertyDeclarationWithInitializer,
ThisNodeIsTypeScriptAmbientDeclaration = ThisNodeIsTypeScript,
ThisNodeIsTypeScriptParameterPropertyAssignment = ThisNodeIsTypeScript | ContainsTypeScriptClassSyntaxExtension,
ThisNodeIsTypeScriptOptionalParameter = ThisNodeIsTypeScript,
ThisNodeIsTypeScriptClassWithSyntaxExtensions = ThisNodeIsTypeScript,
ThisNodeIsTypeScriptEnumDeclaration = ThisNodeIsTypeScript,
ThisNodeIsTypeScriptModuleDeclaration = ThisNodeIsTypeScript,
ThisNodeIsTypeScriptImportEqualsDeclaration = ThisNodeIsTypeScript,
ThisNodeIsTypeScriptExportAssignmentDeclaration = ThisNodeIsTypeScript,
ThisNodeIsTypeScriptDecorator = ThisNodeIsTypeScript,
ThisNodeIsTypeScriptClassSyntaxExtension = ThisNodeIsTypeScript | ContainsTypeScriptClassSyntaxExtension,
ThisNodeIsTypeScriptDecorator = ThisNodeIsTypeScriptClassSyntaxExtension | ContainsTypeScriptDecorator,
// Asserts that this node is ES6, and any subtree that contains it contains ES6.
ThisNodeIsES6 = ES6 | ContainsES6,
@ -491,7 +489,8 @@ namespace ts {
// Asserts that this node is ES6, and any subtree that contains it contains an
// ES6 binding pattern.
ThisNodeIsES6BindingPattern = ThisNodeIsES6 | ContainsES6BindingPattern,
ThisNodeIsES6ParameterBindingPattern = ThisNodeIsES6 | ContainsES6ParameterBindingPattern,
ThisNodeIsES6VariableBindingPattern = ThisNodeIsES6 | ContainsES6VariableBindingPattern,
// Asserts that this node is ES6, and any subtree that contains it contains an
// ES6 rest parameter.
@ -503,30 +502,12 @@ namespace ts {
ThisNodeIsES6SpreadElement = ThisNodeIsES6 | ContainsES6SpreadElement,
ThisNodeIsES6LetOrConst = ThisNodeIsES6 | ContainsES6LetOrConst,
ThisNodeIsES6ArrowFunction = ThisNodeIsES6,
ThisNodeIsES6Generator = ThisNodeIsES6,
ThisNodeIsES6MethodDeclaration = ThisNodeIsES6,
ThisNodeIsES6DestructuringAssignment = ThisNodeIsES6,
ThisNodeIsES6ComputedPropertyName = ThisNodeIsES6,
ThisNodeIsES6ShorthandPropertyAssignment = ThisNodeIsES6,
ThisNodeIsES6ForOfStatement = ThisNodeIsES6,
ThisNodeIsES6ImportDeclaration = ThisNodeIsES6,
ThisNodeIsES6ExportDeclaration = ThisNodeIsES6,
ThisNodeIsES6Export = ThisNodeIsES6,
ThisNodeIsES6NoSubstitutionTemplateLiteral = ThisNodeIsES6,
ThisNodeIsES6TemplateExpression = ThisNodeIsES6,
ThisNodeIsES6TaggedTemplateExpression = ThisNodeIsES6,
ThisNodeIsES6BinaryOrOctalLiteralExpression = ThisNodeIsES6,
// Asserts that this node is ES6, and any subtree that contains it contains an
// ES6 class expression or declaration.
ThisNodeIsES6Class = ThisNodeIsES6,
// Additional markers
ThisNodeCapturesLexicalThis = ContainsCapturedThis,
ThisNodeIsThisKeyword = ContainsLexicalThis,
ThisNodeIsHoistedDeclarationInGenerator = ContainsHoistedDeclarationInES6Generator,
ThisNodeIsCompletionStatementInGenerator = ContainsCompletionStatementInES6Genertator,
ThisNodeIsHoistedDeclaration = ContainsHoistedDeclaration,
ThisNodeIsCompletionStatement = ContainsCompletionStatement,
//
// Masks
@ -538,24 +519,18 @@ namespace ts {
ThisNodeIsES6Mask =
ES6,
// Mask used to clear transform flags that only apply to a node and not a subtree.
ThisNodeFlags =
ThisNodeIsTypeScriptMask |
ThisNodeIsES6Mask,
//
// Transformation Tests
//
ThisNodeNeedsTransformToES6 =
ThisNodeIsTypeScriptMask |
ContainsTypeScriptGeneratedStatements,
ThisNodeIsTypeScriptMask,
ThisNodeNeedsTransformToES5 =
ThisNodeIsES6Mask,
//
// Questions
//
// Queries
//
SubtreeContainsTypeScript =
@ -564,9 +539,6 @@ namespace ts {
SubtreeNeedsTransformToES6 =
SubtreeContainsTypeScript,
SubtreeContainsTypeScriptGeneratedStatements =
ContainsTypeScriptGeneratedStatements,
SubtreeContainsLexicalThis =
ContainsLexicalThis,
@ -577,9 +549,12 @@ namespace ts {
SubtreeContainsRestParameter =
ContainsES6RestParameter,
SubtreeContainsBindingPattern =
ContainsES6BindingPattern,
SubtreeContainsParameterBindingPattern =
ContainsES6ParameterBindingPattern,
SubtreeContainsVariableBindingPattern =
ContainsES6VariableBindingPattern,
SubtreeContainsParameterInitializer =
ContainsES6ParameterInitializer,
@ -595,23 +570,38 @@ namespace ts {
SubtreeNeedsTransformToES5,
ThisParameterNeedsTransform =
ContainsES6BindingPattern |
ContainsES6VariableBindingPattern |
ContainsES6ParameterBindingPattern |
ContainsES6RestParameter |
ContainsES6ParameterInitializer,
SubtreeContainsES6ParameterOrCapturedThis =
ContainsES6ParameterBindingPattern |
ContainsES6ParameterInitializer |
ContainsES6RestParameter |
ContainsCapturedThis,
SubtreeContainsTemplatePlaceholder =
ContainsTemplatePlaceholder,
//
// Scope Exclusions
//
NodeExcludes =
ThisNodeIsTypeScriptMask |
ThisNodeIsES6Mask,
ArrowFunctionScopeExcludes =
ContainsTypeScriptGeneratedStatements |
ContainsES6Yield |
ContainsES6BindingPattern |
ContainsES6VariableBindingPattern |
ContainsES6ParameterBindingPattern |
ContainsES6RestParameter |
ContainsES6ParameterInitializer |
ContainsES6LetOrConst |
ContainsHoistedDeclarationInES6Generator |
ContainsCompletionStatementInES6Genertator,
ContainsHoistedDeclaration |
ContainsCompletionStatement |
ContainsLexicalThis,
FunctionScopeExcludes =
ArrowFunctionScopeExcludes |
@ -621,18 +611,17 @@ namespace ts {
ClassScopeExcludes =
ContainsLexicalThis |
ContainsCapturedThis |
ContainsES6BindingPattern |
ContainsTypeScriptClassSyntaxExtension,
ContainsES6VariableBindingPattern |
ContainsES6ParameterBindingPattern |
ContainsTypeScriptClassSyntaxExtension |
ContainsTypeScriptDecorator,
ModuleScopeExcludes =
ContainsTypeScriptGeneratedStatements |
ContainsES6LetOrConst |
ContainsLexicalThis |
ContainsCapturedThis |
ContainsES6BindingPattern,
BlockScopeExcludes =
ContainsTypeScriptGeneratedStatements,
ContainsES6VariableBindingPattern |
ContainsES6ParameterBindingPattern,
CallOrArrayLiteralExcludes =
ContainsES6SpreadElement,
@ -679,6 +668,7 @@ namespace ts {
// Only set when the parser was in some interesting context (like async/yield).
/* @internal */ parserContextFlags?: ParserContextFlags;
/* @internal */ transformFlags?: TransformFlags;
/* @internal */ excludeTransformFlags?: TransformFlags;
decorators?: NodeArray<Decorator>; // Array of decorators (in document order)
modifiers?: ModifiersArray; // Array of modifiers
/* @internal */ id?: number; // Unique id (used to look up NodeLinks)
@ -784,6 +774,8 @@ namespace ts {
}
// @kind(SyntaxKind.VariableDeclaration)
// @factoryhidden("decorators", true)
// @factoryhidden("modifiers", true)
export interface VariableDeclaration extends Declaration {
// @factoryhidden
parent?: VariableDeclarationList;
@ -803,7 +795,6 @@ namespace ts {
// @factoryparam
dotDotDotToken?: Node; // Present on rest parameter
name: Identifier | BindingPattern; // Declared parameter name
// @factoryparam
questionToken?: Node; // Present on optional parameter
type?: TypeNode; // Optional type annotation
initializer?: Expression; // Optional initializer
@ -844,10 +835,10 @@ namespace ts {
// @kind(SyntaxKind.PropertyAssignment)
// @factoryhidden("decorators", true)
// @factoryhidden("modifiers", true)
// @factoryhidden("questionToken", true)
export interface PropertyAssignment extends ObjectLiteralElement {
_propertyAssignmentBrand: any;
name: PropertyName;
// @factoryparam
questionToken?: Node;
initializer: Expression;
}
@ -855,9 +846,9 @@ namespace ts {
// @kind(SyntaxKind.ShorthandPropertyAssignment)
// @factoryhidden("decorators", true)
// @factoryhidden("modifiers", true)
// @factoryhidden("questionToken", true)
export interface ShorthandPropertyAssignment extends ObjectLiteralElement {
name: Identifier;
// @factoryparam
questionToken?: Node;
}
@ -905,7 +896,7 @@ namespace ts {
// @factoryparam
questionToken?: Node;
// @visitor("visitBlockOrExpressionInNewLexicalScope")
// @visitor("visitBlockOrExpressionInNewLexicalEnvironment")
body?: Block | Expression;
}
@ -915,7 +906,7 @@ namespace ts {
export interface FunctionDeclaration extends FunctionLikeDeclaration, DeclarationStatement {
name?: Identifier;
// @visitor("visitBlockInNewLexicalScope")
// @visitor("visitBlockInNewLexicalEnvironment")
body?: Block;
}
@ -971,7 +962,7 @@ namespace ts {
export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement {
_accessorDeclarationBrand: any;
name: PropertyName;
// @visitor("visitBlockInNewLexicalScope")
// @visitor("visitBlockInNewLexicalEnvironment")
body: Block;
}
@ -1108,11 +1099,6 @@ namespace ts {
_postfixExpressionBrand: any;
}
// @kind(SyntaxKind.TrueKeyword, { create: false })
// @kind(SyntaxKind.FalseKeyword, { create: false })
// @kind(SyntaxKind.NullKeyword, { create: false })
// @kind(SyntaxKind.ThisKeyword)
// @kind(SyntaxKind.SuperKeyword, { create: false })
export interface LeftHandSideExpression extends PostfixExpression {
_leftHandSideExpressionBrand: any;
}
@ -1121,6 +1107,11 @@ namespace ts {
_memberExpressionBrand: any;
}
// @kind(SyntaxKind.TrueKeyword)
// @kind(SyntaxKind.FalseKeyword)
// @kind(SyntaxKind.NullKeyword, { create: false })
// @kind(SyntaxKind.ThisKeyword)
// @kind(SyntaxKind.SuperKeyword)
export interface PrimaryExpression extends MemberExpression {
_primaryExpressionBrand: any;
}
@ -1177,7 +1168,7 @@ namespace ts {
export interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclaration {
name?: Identifier;
// @visitor("visitBlockOrExpressionInNewLexicalScope")
// @visitor("visitBlockOrExpressionInNewLexicalEnvironment")
body: Block | Expression; // Required, whereas the member inherited from FunctionDeclaration is optional
}
@ -1372,6 +1363,8 @@ namespace ts {
}
// @kind(SyntaxKind.VariableStatement)
// @factoryhidden("decorators", false)
// @factoryhidden("modifiers", false)
export interface VariableStatement extends Statement {
declarationList: VariableDeclarationList;
}
@ -1384,11 +1377,16 @@ namespace ts {
// @kind(SyntaxKind.IfStatement)
export interface IfStatement extends Statement {
expression: Expression;
// @visitor("visitStatement")
thenStatement: Statement;
// @visitor("visitStatement")
elseStatement?: Statement;
}
export interface IterationStatement extends Statement {
// @visitor("visitStatement")
statement: Statement;
}
@ -1440,6 +1438,8 @@ namespace ts {
// @kind(SyntaxKind.WithStatement)
export interface WithStatement extends Statement {
expression: Expression;
// @visitor("visitStatement")
statement: Statement;
}
@ -1470,6 +1470,8 @@ namespace ts {
// @kind(SyntaxKind.LabeledStatement)
export interface LabeledStatement extends Statement {
label: Identifier;
// @visitor("visitStatement")
statement: Statement;
}
@ -1531,6 +1533,7 @@ namespace ts {
// @kind(SyntaxKind.HeritageClause)
export interface HeritageClause extends Node {
// @factoryparam
token: SyntaxKind;
types?: NodeArray<ExpressionWithTypeArguments>;
}
@ -1562,7 +1565,7 @@ namespace ts {
export interface ModuleDeclaration extends DeclarationStatement {
name: Identifier | LiteralExpression;
// @visitor("visitModuleBlockOrModuleDeclarationInNewLexicalScope")
// @visitor("visitModuleBlockOrModuleDeclarationInNewLexicalEnvironment")
body: ModuleBlock | ModuleDeclaration;
}

View file

@ -11,7 +11,7 @@ namespace ts {
export interface SynthesizedNode extends Node {
leadingCommentRanges?: CommentRange[];
trailingCommentRanges?: CommentRange[];
startsOnNewLine: boolean;
startsOnNewLine?: boolean;
}
export function getDeclarationOfKind(symbol: Symbol, kind: SyntaxKind): Declaration {
@ -435,12 +435,22 @@ namespace ts {
/** Gets the original node for a node that was updated via one of the factory.updateX functions */
export function getOriginalNode(node: Node) {
while (node.original) {
while (node && node.original) {
node = node.original;
}
return node;
}
export function getOriginalNodeIf<T extends Node>(node: T, nodeTest: (node: Node) => node is T): T {
while (node && node.original) {
let original = node.original;
if (nodeTest(original)) {
node = original;
}
}
return node;
}
export function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode: SourceFile) {
// If parameter/type parameter, the prev token trailing comments are part of this node too
@ -651,11 +661,11 @@ namespace ts {
return node && (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor);
}
export function isClassLike(node: Node): boolean {
export function isClassLike(node: Node): node is ClassLikeDeclaration {
return node && (node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression);
}
export function isFunctionLike(node: Node): boolean {
export function isFunctionLike(node: Node): node is FunctionLikeDeclaration {
if (node) {
switch (node.kind) {
case SyntaxKind.Constructor:
@ -685,27 +695,33 @@ namespace ts {
return node && node.kind === SyntaxKind.MethodDeclaration && node.parent.kind === SyntaxKind.ObjectLiteralExpression;
}
export function getContainingFunction(node: Node): FunctionLikeDeclaration {
export function getContainingFunction(node: Node): FunctionLikeDeclaration;
export function getContainingFunction(node: Node, getAncestorOrSelf: (offset: number) => Node, offset: number): FunctionLikeDeclaration;
export function getContainingFunction(node: Node, getAncestorOrSelf?: (offset: number) => Node, offset?: number): FunctionLikeDeclaration {
while (true) {
node = node.parent;
node = getAncestorOrSelf ? getAncestorOrSelf(++offset) : node.parent;
if (!node || isFunctionLike(node)) {
return <FunctionLikeDeclaration>node;
}
}
}
export function getContainingClass(node: Node): ClassLikeDeclaration {
export function getContainingClass(node: Node): ClassLikeDeclaration;
export function getContainingClass(node: Node, getAncestorOrSelf: (offset: number) => Node, offset: number): ClassLikeDeclaration;
export function getContainingClass(node: Node, getAncestorOrSelf?: (offset: number) => Node, offset?: number): ClassLikeDeclaration {
while (true) {
node = node.parent;
node = getAncestorOrSelf ? getAncestorOrSelf(++offset) : node.parent;
if (!node || isClassLike(node)) {
return <ClassLikeDeclaration>node;
}
}
}
export function getThisContainer(node: Node, includeArrowFunctions: boolean): Node {
export function getThisContainer(node: Node, includeArrowFunctions: boolean): Node;
export function getThisContainer(node: Node, includeArrowFunctions: boolean, getAncestorOrSelf: (offset: number) => Node, offset: number): Node;
export function getThisContainer(node: Node, includeArrowFunctions: boolean, getAncestorOrSelf?: (offset: number) => Node, offset?: number): Node {
while (true) {
node = node.parent;
node = getAncestorOrSelf ? getAncestorOrSelf(++offset) : node.parent;
if (!node) {
return undefined;
}
@ -715,7 +731,7 @@ namespace ts {
// then the computed property is not a 'this' container.
// A computed property name in a class needs to be a this container
// so that we can error on it.
if (isClassLike(node.parent.parent)) {
if (isClassLike(getAncestorOrSelf ? getAncestorOrSelf(offset + 2) : node.parent.parent)) {
return node;
}
// If this is a computed property, then the parent should not
@ -723,19 +739,20 @@ namespace ts {
// in an object literal, like a method or accessor. But in order for
// such a parent to be a this container, the reference must be in
// the *body* of the container.
node = node.parent;
node = getAncestorOrSelf ? getAncestorOrSelf(++offset) : node.parent;
break;
case SyntaxKind.Decorator:
// Decorators are always applied outside of the body of a class or method.
if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) {
if (isParameter(getAncestorOrSelf ? getAncestorOrSelf(offset + 1) : node.parent)
&& isClassElement(getAncestorOrSelf ? getAncestorOrSelf(offset + 2) : node.parent.parent)) {
// If the decorator's parent is a Parameter, we resolve the this container from
// the grandparent class declaration.
node = node.parent.parent;
node = getAncestorOrSelf ? getAncestorOrSelf(offset += 2) : node.parent.parent;
}
else if (isClassElement(node.parent)) {
else if (isClassElement(getAncestorOrSelf ? getAncestorOrSelf(offset + 1) : node.parent)) {
// If the decorator's parent is a class element, we resolve the 'this' container
// from the parent class declaration.
node = node.parent;
node = getAncestorOrSelf ? getAncestorOrSelf(++offset) : node.parent;
}
break;
case SyntaxKind.ArrowFunction:
@ -760,9 +777,11 @@ namespace ts {
}
}
export function getSuperContainer(node: Node, includeFunctions: boolean): Node {
export function getSuperContainer(node: Node, includeFunctions: boolean): Node;
export function getSuperContainer(node: Node, includeFunctions: boolean, getAncestorOrSelf: (offset: number) => Node, offset: number): Node;
export function getSuperContainer(node: Node, includeFunctions: boolean, getAncestorOrSelf?: (offset: number) => Node, offset?: number): Node {
while (true) {
node = node.parent;
node = getAncestorOrSelf ? getAncestorOrSelf(++offset) : node.parent;
if (!node) return node;
switch (node.kind) {
case SyntaxKind.ComputedPropertyName:
@ -770,7 +789,7 @@ namespace ts {
// then the computed property is not a 'super' container.
// A computed property name in a class needs to be a super container
// so that we can error on it.
if (isClassLike(node.parent.parent)) {
if (isClassLike(getAncestorOrSelf ? getAncestorOrSelf(offset + 2) : node.parent.parent)) {
return node;
}
// If this is a computed property, then the parent should not
@ -778,19 +797,20 @@ namespace ts {
// in an object literal, like a method or accessor. But in order for
// such a parent to be a super container, the reference must be in
// the *body* of the container.
node = node.parent;
node = getAncestorOrSelf ? getAncestorOrSelf(++offset) : node.parent;
break;
case SyntaxKind.Decorator:
// Decorators are always applied outside of the body of a class or method.
if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) {
if (isParameter(getAncestorOrSelf ? getAncestorOrSelf(offset + 1) : node.parent)
&& isClassElement(getAncestorOrSelf ? getAncestorOrSelf(offset + 2) : node.parent.parent)) {
// If the decorator's parent is a Parameter, we resolve the this container from
// the grandparent class declaration.
node = node.parent.parent;
node = getAncestorOrSelf ? getAncestorOrSelf(offset += 2) : node.parent.parent;
}
else if (isClassElement(node.parent)) {
else if (isClassElement(getAncestorOrSelf ? getAncestorOrSelf(offset + 1) : node.parent)) {
// If the decorator's parent is a class element, we resolve the 'this' container
// from the parent class declaration.
node = node.parent;
node = getAncestorOrSelf ? getAncestorOrSelf(++offset) : node.parent;
}
break;
case SyntaxKind.FunctionDeclaration:
@ -872,7 +892,7 @@ namespace ts {
export function nodeIsDecorated(node: Node): boolean {
switch (node.kind) {
case SyntaxKind.ClassDeclaration:
if (node.decorators) {
if (node.decorators && node.decorators.length > 0) {
return true;
}
@ -880,14 +900,14 @@ namespace ts {
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.Parameter:
if (node.decorators) {
if (node.decorators && node.decorators.length > 0) {
return true;
}
return false;
case SyntaxKind.GetAccessor:
if ((<FunctionLikeDeclaration>node).body && node.decorators) {
if ((<FunctionLikeDeclaration>node).body && node.decorators && node.decorators.length > 0) {
return true;
}
@ -895,7 +915,7 @@ namespace ts {
case SyntaxKind.MethodDeclaration:
case SyntaxKind.SetAccessor:
if ((<FunctionLikeDeclaration>node).body && node.decorators) {
if ((<FunctionLikeDeclaration>node).body && node.decorators && node.decorators.length > 0) {
return true;
}
@ -926,7 +946,7 @@ namespace ts {
* Returns whether the node is part of an expression.
* @param node The node to test
*/
export function isExpression(node: Node): boolean;
export function isPartOfExpression(node: Node): boolean;
/**
* Returns whether the node is part of an expression.
@ -936,7 +956,7 @@ namespace ts {
* @param offset The offset in the node stack used to get the ancestor of the current node
* from the emitter's node stack.
*/
export function isExpression(node: Node, getAncestorOrSelf: (offset: number) => Node, offset: number): boolean;
export function isPartOfExpression(node: Node, getAncestorOrSelf: (offset: number) => Node, offset: number): boolean;
/**
* Returns whether the node is part of an expression.
@ -953,7 +973,7 @@ namespace ts {
* current node on the top of the node stack, an offset of one (1) refers to its parent, an
* offset of two (2) refers to the grandparent, and so on.
*/
export function isExpression(node: Node, getAncestorOrSelf?: (offset: number) => Node, offset?: number): boolean {
export function isPartOfExpression(node: Node, getAncestorOrSelf?: (offset: number) => Node, offset?: number): boolean {
let parent: Node;
switch (node.kind) {
case SyntaxKind.ThisKeyword:
@ -1049,7 +1069,7 @@ namespace ts {
case SyntaxKind.ExpressionWithTypeArguments:
return (<ExpressionWithTypeArguments>parent).expression === node && isExpressionWithTypeArgumentsInClassExtendsClause(parent, getAncestorOrSelf, offset + 1);
default:
if (isExpression(parent, getAncestorOrSelf, offset)) {
if (isPartOfExpression(parent, getAncestorOrSelf, offset)) {
return true;
}
}
@ -1057,6 +1077,150 @@ namespace ts {
return false;
}
export function getExpressionPrecedence(expr: Expression) {
return getOperatorPrecedence(expr.kind, getOperator(expr), isNewExpression(expr) && !expr.arguments)
}
export function getBinaryOperatorPrecedence(operator: SyntaxKind) {
return getOperatorPrecedence(SyntaxKind.BinaryExpression, operator);
}
function getOperator(expr: Expression) {
return isBinaryExpression(expr)
? expr.operatorToken.kind
: isPrefixUnaryExpression(expr) || isPostfixUnaryExpression(expr)
? expr.operator
: undefined;
}
function getOperatorPrecedence(kind: SyntaxKind, operator: SyntaxKind, isNewExpressionWithoutArguments?: boolean) {
switch (kind) {
case SyntaxKind.ThisKeyword:
case SyntaxKind.SuperKeyword:
case SyntaxKind.Identifier:
case SyntaxKind.NullKeyword:
case SyntaxKind.TrueKeyword:
case SyntaxKind.FalseKeyword:
case SyntaxKind.NumericLiteral:
case SyntaxKind.StringLiteral:
case SyntaxKind.ArrayLiteralExpression:
case SyntaxKind.ObjectLiteralExpression:
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
case SyntaxKind.ClassExpression:
case SyntaxKind.JsxElement:
case SyntaxKind.JsxSelfClosingElement:
case SyntaxKind.RegularExpressionLiteral:
case SyntaxKind.NoSubstitutionTemplateLiteral:
case SyntaxKind.TemplateExpression:
case SyntaxKind.ParenthesizedExpression:
return 19;
case SyntaxKind.TaggedTemplateExpression:
case SyntaxKind.PropertyAccessExpression:
case SyntaxKind.ElementAccessExpression:
return 18;
case SyntaxKind.NewExpression:
return isNewExpressionWithoutArguments ? 17 : 18;
case SyntaxKind.CallExpression:
return 17;
case SyntaxKind.PostfixUnaryExpression:
return 16;
case SyntaxKind.PrefixUnaryExpression:
case SyntaxKind.TypeOfExpression:
case SyntaxKind.VoidExpression:
case SyntaxKind.DeleteExpression:
case SyntaxKind.AwaitExpression:
return 15;
case SyntaxKind.BinaryExpression:
switch (operator) {
case SyntaxKind.ExclamationToken:
case SyntaxKind.TildeToken:
return 15;
case SyntaxKind.AsteriskToken:
case SyntaxKind.SlashToken:
case SyntaxKind.PercentToken:
return 14;
case SyntaxKind.PlusToken:
case SyntaxKind.MinusToken:
return 13;
case SyntaxKind.LessThanLessThanToken:
case SyntaxKind.GreaterThanGreaterThanToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
return 12;
case SyntaxKind.LessThanToken:
case SyntaxKind.LessThanEqualsToken:
case SyntaxKind.GreaterThanToken:
case SyntaxKind.GreaterThanEqualsToken:
case SyntaxKind.InKeyword:
case SyntaxKind.InstanceOfKeyword:
return 11;
case SyntaxKind.EqualsEqualsToken:
case SyntaxKind.EqualsEqualsEqualsToken:
case SyntaxKind.ExclamationEqualsToken:
case SyntaxKind.ExclamationEqualsEqualsToken:
return 10;
case SyntaxKind.AmpersandToken:
return 9;
case SyntaxKind.CaretToken:
return 8;
case SyntaxKind.BarToken:
return 7;
case SyntaxKind.AmpersandAmpersandToken:
return 6;
case SyntaxKind.BarBarToken:
return 5;
case SyntaxKind.EqualsToken:
case SyntaxKind.PlusEqualsToken:
case SyntaxKind.MinusEqualsToken:
case SyntaxKind.AsteriskEqualsToken:
case SyntaxKind.SlashEqualsToken:
case SyntaxKind.PercentEqualsToken:
case SyntaxKind.LessThanLessThanEqualsToken:
case SyntaxKind.GreaterThanGreaterThanEqualsToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:
case SyntaxKind.AmpersandEqualsToken:
case SyntaxKind.CaretEqualsToken:
case SyntaxKind.BarEqualsToken:
return 3;
case SyntaxKind.CommaToken:
return 0;
default:
return -1;
}
case SyntaxKind.ConditionalExpression:
return 4;
case SyntaxKind.YieldExpression:
return 2;
case SyntaxKind.SpreadElementExpression:
return 1;
default:
return -1;
}
}
export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean) {
let moduleState = getModuleInstanceState(node);
return moduleState === ModuleInstanceState.Instantiated ||
@ -1262,7 +1426,7 @@ namespace ts {
case SyntaxKind.LabeledStatement:
case SyntaxKind.ReturnStatement:
case SyntaxKind.SwitchStatement:
case SyntaxKind.ThrowKeyword:
case SyntaxKind.ThrowStatement:
case SyntaxKind.TryStatement:
case SyntaxKind.VariableStatement:
case SyntaxKind.WhileStatement:
@ -1275,8 +1439,12 @@ namespace ts {
return false;
}
export function isStatementOrDeclarationStatement(n: Node): n is Statement {
return isStatement(n) || isDeclarationStatement(n);
}
// True if the given identifier, string literal, or number literal is the name of a declaration node
export function isDeclarationName(name: Node): boolean {
export function isDeclarationName(name: Node): name is Identifier | StringLiteral | LiteralExpression {
if (name.kind !== SyntaxKind.Identifier && name.kind !== SyntaxKind.StringLiteral && name.kind !== SyntaxKind.NumericLiteral) {
return false;
}
@ -2017,7 +2185,7 @@ namespace ts {
return 0;
}
export function isLeftHandSideExpression(expr: Node): boolean {
export function isLeftHandSideExpression(expr: Node): expr is LeftHandSideExpression {
if (expr) {
switch (expr.kind) {
case SyntaxKind.PropertyAccessExpression:

View file

@ -29,7 +29,7 @@ class TypeWriterWalker {
}
private visitNode(node: ts.Node): void {
if (ts.isExpression(node) || node.kind === ts.SyntaxKind.Identifier) {
if (ts.isPartOfExpression(node) || node.kind === ts.SyntaxKind.Identifier) {
this.logTypeAndSymbol(node);
}

View file

@ -59,7 +59,7 @@ namespace ts.BreakpointResolver {
function spanInNode(node: Node): TextSpan {
if (node) {
if (isExpression(node)) {
if (isPartOfExpression(node)) {
if (node.parent.kind === SyntaxKind.DoStatement) {
// Set span as if on while keyword
return spanInPreviousNode(node);

View file

@ -681,7 +681,7 @@ namespace ts.formatting {
}
static NodeIsInDecoratorContext(node: Node): boolean {
while (isExpression(node)) {
while (isPartOfExpression(node)) {
node = node.parent;
}
return node.kind === SyntaxKind.Decorator;

View file

@ -129,7 +129,6 @@ var CC = (function () {
}
return CC;
})();
var CC;
(function (CC) {
CC.bar = 1;
})(CC || (CC = {}));

View file

@ -156,7 +156,6 @@ var c = (function () {
}
return c;
})();
var c;
(function (c) {
c.bar = 1;
})(c || (c = {}));

View file

@ -42,7 +42,7 @@ module M {
//// [asyncAwaitIsolatedModules_es6.js]
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {
return new Promise(function (resolve, reject) {
generator = generator.call(thisArg, _arguments);
generator = generator.apply(thisArg, _arguments);
function cast(value) { return value instanceof Promise && value.constructor === Promise ? value : new Promise(function (resolve) { resolve(value); }); }
function onfulfill(value) { try { step("next", value); } catch (e) { reject(e); } }
function onreject(value) { try { step("throw", value); } catch (e) { reject(e); } }

View file

@ -42,7 +42,7 @@ module M {
//// [asyncAwait_es6.js]
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {
return new Promise(function (resolve, reject) {
generator = generator.call(thisArg, _arguments);
generator = generator.apply(thisArg, _arguments);
function cast(value) { return value instanceof Promise && value.constructor === Promise ? value : new Promise(function (resolve) { resolve(value); }); }
function onfulfill(value) { try { step("next", value); } catch (e) { reject(e); } }
function onreject(value) { try { step("throw", value); } catch (e) { reject(e); } }

View file

@ -3,5 +3,4 @@ var v = class C {};
//// [classExpressionES61.js]
var v = class C {
}
;
};

View file

@ -6,5 +6,4 @@ var v = class C extends D {};
class D {
}
var v = class C extends D {
}
;
};

View file

@ -11,20 +11,17 @@ let C = class class_1 extends class class_2 extends class class_3 {
constructor() {
this.a = 1;
}
}
{
} {
constructor(...args) {
super(...args);
this.b = 2;
}
}
{
} {
constructor(...args) {
super(...args);
this.c = 3;
}
}
;
};
let c = new C();
c.a;
c.b;

View file

@ -6,6 +6,5 @@ function* g() {
//// [generatorTypeCheck55.js]
function* g() {
var x = class C extends (yield) {
}
;
};
}

View file

@ -13,6 +13,5 @@ function* g() {
*[yield 0]() {
yield 0;
}
}
;
};
}

File diff suppressed because it is too large Load diff