Update LKG

This commit is contained in:
Mohamed Hegazy
2017-08-25 15:36:13 -07:00
parent 187a21cbac
commit 2a2773fbb4
9 changed files with 761 additions and 625 deletions
+121 -110
View File
@@ -3521,7 +3521,7 @@ var ts;
Convert_function_to_an_ES2015_class: diag(95001, ts.DiagnosticCategory.Message, "Convert_function_to_an_ES2015_class_95001", "Convert function to an ES2015 class"),
Convert_function_0_to_class: diag(95002, ts.DiagnosticCategory.Message, "Convert_function_0_to_class_95002", "Convert function '{0}' to class"),
Extract_function: diag(95003, ts.DiagnosticCategory.Message, "Extract_function_95003", "Extract function"),
Extract_function_into_0: diag(95004, ts.DiagnosticCategory.Message, "Extract_function_into_0_95004", "Extract function into '{0}'"),
Extract_function_into_0: diag(95004, ts.DiagnosticCategory.Message, "Extract_function_into_0_95004", "Extract function into {0}"),
};
})(ts || (ts = {}));
var ts;
@@ -6876,9 +6876,9 @@ var ts;
|| kind === 265;
}
ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment;
function nodeIsSynthesized(node) {
return ts.positionIsSynthesized(node.pos)
|| ts.positionIsSynthesized(node.end);
function nodeIsSynthesized(range) {
return ts.positionIsSynthesized(range.pos)
|| ts.positionIsSynthesized(range.end);
}
ts.nodeIsSynthesized = nodeIsSynthesized;
function getOriginalSourceFile(sourceFile) {
@@ -18801,7 +18801,10 @@ var ts;
}
return true;
}
if (usage.parent.kind === 246) {
if (usage.parent.kind === 246 || (usage.parent.kind === 243 && usage.parent.isExportEquals)) {
return true;
}
if (usage.kind === 243 && usage.isExportEquals) {
return true;
}
var container = ts.getEnclosingBlockScopeContainer(declaration);
@@ -23469,6 +23472,9 @@ var ts;
}
return signature.resolvedReturnType;
}
function isResolvingReturnTypeOfSignature(signature) {
return !signature.resolvedReturnType && findResolutionCycleStartIndex(signature, 3) >= 0;
}
function getRestTypeOfSignature(signature) {
if (signature.hasRestParameter) {
var type = getTypeOfSymbol(ts.lastOrUndefined(signature.parameters));
@@ -28576,7 +28582,7 @@ var ts;
return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl));
}
var signature = getContextualSignatureForFunctionLikeDeclaration(functionDecl);
if (signature) {
if (signature && !isResolvingReturnTypeOfSignature(signature)) {
return getReturnTypeOfSignature(signature);
}
return undefined;
@@ -30866,7 +30872,7 @@ var ts;
return result;
}
function isJavaScriptConstructor(node) {
if (ts.isInJavaScriptFile(node)) {
if (node && ts.isInJavaScriptFile(node)) {
if (ts.getJSDocClassTag(node))
return true;
var symbol = ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) ? getSymbolOfNode(node) :
@@ -30876,6 +30882,20 @@ var ts;
}
return false;
}
function getJavaScriptClassType(symbol) {
if (ts.isDeclarationOfFunctionOrClassExpression(symbol)) {
symbol = getSymbolOfNode(symbol.valueDeclaration.initializer);
}
if (isJavaScriptConstructor(symbol.valueDeclaration)) {
return getInferredClassType(symbol);
}
if (symbol.flags & 3) {
var valueType = getTypeOfSymbol(symbol);
if (valueType.symbol && !isInferredClassType(valueType) && isJavaScriptConstructor(valueType.symbol.valueDeclaration)) {
return getInferredClassType(valueType.symbol);
}
}
}
function getInferredClassType(symbol) {
var links = getSymbolLinks(symbol);
if (!links.inferredClassType) {
@@ -30904,13 +30924,11 @@ var ts;
var funcSymbol = node.expression.kind === 71 ?
getResolvedSymbol(node.expression) :
checkExpression(node.expression).symbol;
if (funcSymbol && ts.isDeclarationOfFunctionOrClassExpression(funcSymbol)) {
funcSymbol = getSymbolOfNode(funcSymbol.valueDeclaration.initializer);
var type = funcSymbol && getJavaScriptClassType(funcSymbol);
if (type) {
return type;
}
if (funcSymbol && funcSymbol.flags & 16 && (funcSymbol.members || ts.getJSDocClassTag(funcSymbol.valueDeclaration))) {
return getInferredClassType(funcSymbol);
}
else if (noImplicitAny) {
if (noImplicitAny) {
error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
}
return anyType;
@@ -33057,6 +33075,7 @@ var ts;
: 4;
case 229:
case 232:
case 240:
return 2 | 1;
case 237:
var result_3 = 0;
@@ -36229,6 +36248,14 @@ var ts;
return type.flags & 32768 && getSignaturesOfType(type, 0).length > 0;
}
function getTypeReferenceSerializationKind(typeName, location) {
typeName = ts.getParseTreeNode(typeName, ts.isEntityName);
if (!typeName)
return ts.TypeReferenceSerializationKind.Unknown;
if (location) {
location = ts.getParseTreeNode(location);
if (!location)
return ts.TypeReferenceSerializationKind.Unknown;
}
var valueSymbol = resolveEntityName(typeName, 107455, true, false, location);
var typeSymbol = resolveEntityName(typeName, 793064, true, false, location);
if (valueSymbol && valueSymbol === typeSymbol) {
@@ -39686,6 +39713,10 @@ var ts;
return createCall(createFunctionExpression(undefined, undefined, undefined, undefined, param ? [param] : [], undefined, createBlock(statements, true)), undefined, paramValue ? [paramValue] : []);
}
ts.createImmediatelyInvokedFunctionExpression = createImmediatelyInvokedFunctionExpression;
function createImmediatelyInvokedArrowFunction(statements, param, paramValue) {
return createCall(createArrowFunction(undefined, undefined, param ? [param] : [], undefined, undefined, createBlock(statements, true)), undefined, paramValue ? [paramValue] : []);
}
ts.createImmediatelyInvokedArrowFunction = createImmediatelyInvokedArrowFunction;
function createComma(left, right) {
return createBinary(left, 26, right);
}
@@ -40769,9 +40800,17 @@ var ts;
case 288: return ts.updatePartiallyEmittedExpression(outerExpression, expression);
}
}
function isIgnorableParen(node) {
return node.kind === 185
&& ts.nodeIsSynthesized(node)
&& ts.nodeIsSynthesized(ts.getSourceMapRange(node))
&& ts.nodeIsSynthesized(ts.getCommentRange(node))
&& !ts.some(ts.getSyntheticLeadingComments(node))
&& !ts.some(ts.getSyntheticTrailingComments(node));
}
function recreateOuterExpressions(outerExpression, innerExpression, kinds) {
if (kinds === void 0) { kinds = 7; }
if (outerExpression && isOuterExpression(outerExpression, kinds)) {
if (outerExpression && isOuterExpression(outerExpression, kinds) && !isIgnorableParen(outerExpression)) {
return updateOuterExpression(outerExpression, recreateOuterExpressions(outerExpression.expression, innerExpression));
}
return innerExpression;
@@ -41997,7 +42036,7 @@ var ts;
}
else {
var name = node.name;
if (!uniqueExports.get(ts.unescapeLeadingUnderscores(name.escapedText))) {
if (name && !uniqueExports.get(ts.unescapeLeadingUnderscores(name.escapedText))) {
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name);
uniqueExports.set(ts.unescapeLeadingUnderscores(name.escapedText), true);
exportedNames = ts.append(exportedNames, name);
@@ -42670,8 +42709,10 @@ var ts;
ts.setEmitFlags(statement, 1536 | 384);
statements.push(statement);
ts.addRange(statements, context.endLexicalEnvironment());
var iife = ts.createImmediatelyInvokedArrowFunction(statements);
ts.setEmitFlags(iife, 33554432);
var varStatement = ts.createVariableStatement(undefined, ts.createVariableDeclarationList([
ts.createVariableDeclaration(ts.getLocalName(node, false, false), undefined, ts.createImmediatelyInvokedFunctionExpression(statements))
ts.createVariableDeclaration(ts.getLocalName(node, false, false), undefined, iife)
]));
ts.setOriginalNode(varStatement, node);
ts.setCommentRange(varStatement, node);
@@ -43277,7 +43318,7 @@ var ts;
var name = ts.getMutableClone(node);
name.flags &= ~8;
name.original = undefined;
name.parent = currentScope;
name.parent = ts.getParseTreeNode(currentScope);
if (useFallback) {
return ts.createLogicalAnd(ts.createStrictInequality(ts.createTypeOf(name), ts.createLiteral("undefined")), name);
}
@@ -44361,7 +44402,7 @@ var ts;
chunkObject.push(ts.createPropertyAssignment(p.name, ts.visitNode(p.initializer, visitor, ts.isExpression)));
}
else {
chunkObject.push(e);
chunkObject.push(ts.visitNode(e, visitor, ts.isObjectLiteralElementLike));
}
}
}
@@ -45307,58 +45348,12 @@ var ts;
&& node.kind === 219
&& !node.expression;
}
function isClassLikeVariableStatement(node) {
if (!ts.isVariableStatement(node))
return false;
var variable = ts.singleOrUndefined(node.declarationList.declarations);
return variable
&& variable.initializer
&& ts.isIdentifier(variable.name)
&& (ts.isClassLike(variable.initializer)
|| (ts.isAssignmentExpression(variable.initializer)
&& ts.isIdentifier(variable.initializer.left)
&& ts.isClassLike(variable.initializer.right)));
}
function isTypeScriptClassWrapper(node) {
var call = ts.tryCast(node, ts.isCallExpression);
if (!call || ts.isParseTreeNode(call) ||
ts.some(call.typeArguments) ||
ts.some(call.arguments)) {
return false;
}
var func = ts.tryCast(ts.skipOuterExpressions(call.expression), ts.isFunctionExpression);
if (!func || ts.isParseTreeNode(func) ||
ts.some(func.typeParameters) ||
ts.some(func.parameters) ||
func.type ||
!func.body) {
return false;
}
var statements = func.body.statements;
if (statements.length < 2) {
return false;
}
var firstStatement = statements[0];
if (ts.isParseTreeNode(firstStatement) ||
!ts.isClassLike(firstStatement) &&
!isClassLikeVariableStatement(firstStatement)) {
return false;
}
var lastStatement = ts.elementAt(statements, -1);
var returnStatement = ts.tryCast(ts.isVariableStatement(lastStatement) ? ts.elementAt(statements, -2) : lastStatement, ts.isReturnStatement);
if (!returnStatement ||
!returnStatement.expression ||
!ts.isIdentifier(ts.skipOuterExpressions(returnStatement.expression))) {
return false;
}
return true;
}
function shouldVisitNode(node) {
return (node.transformFlags & 128) !== 0
|| convertedLoopState !== undefined
|| (hierarchyFacts & 4096 && (ts.isStatement(node) || (node.kind === 207)))
|| (ts.isIterationStatement(node, false) && shouldConvertIterationStatementBody(node))
|| isTypeScriptClassWrapper(node);
|| (ts.getEmitFlags(node) & 33554432) !== 0;
}
function visitor(node) {
if (shouldVisitNode(node)) {
@@ -46838,7 +46833,7 @@ var ts;
return ts.visitEachChild(node, visitor, context);
}
function visitCallExpression(node) {
if (isTypeScriptClassWrapper(node)) {
if (ts.getEmitFlags(node) & 33554432) {
return visitTypeScriptClassWrapper(node);
}
if (node.transformFlags & 64) {
@@ -46847,7 +46842,7 @@ var ts;
return ts.updateCall(node, ts.visitNode(node.expression, callExpressionVisitor, ts.isExpression), undefined, ts.visitNodes(node.arguments, visitor, ts.isExpression));
}
function visitTypeScriptClassWrapper(node) {
var body = ts.cast(ts.skipOuterExpressions(node.expression), ts.isFunctionExpression).body;
var body = ts.cast(ts.cast(ts.skipOuterExpressions(node.expression), ts.isArrowFunction).body, ts.isBlock);
var classStatements = ts.visitNodes(body.statements, visitor, ts.isStatement, 0, 1);
var remainingStatements = ts.visitNodes(body.statements, visitor, ts.isStatement, 1, body.statements.length - 1);
var varStatement = ts.cast(ts.firstOrUndefined(classStatements), ts.isVariableStatement);
@@ -48042,8 +48037,12 @@ var ts;
}
function transformAndEmitContinueStatement(node) {
var label = findContinueTarget(node.label ? ts.unescapeLeadingUnderscores(node.label.escapedText) : undefined);
ts.Debug.assert(label > 0, "Expected continue statment to point to a valid Label.");
emitBreak(label, node);
if (label > 0) {
emitBreak(label, node);
}
else {
emitStatement(node);
}
}
function visitContinueStatement(node) {
if (inStatementContainingYield) {
@@ -48056,8 +48055,12 @@ var ts;
}
function transformAndEmitBreakStatement(node) {
var label = findBreakTarget(node.label ? ts.unescapeLeadingUnderscores(node.label.escapedText) : undefined);
ts.Debug.assert(label > 0, "Expected break statment to point to a valid Label.");
emitBreak(label, node);
if (label > 0) {
emitBreak(label, node);
}
else {
emitStatement(node);
}
}
function visitBreakStatement(node) {
if (inStatementContainingYield) {
@@ -48481,43 +48484,45 @@ var ts;
return false;
}
function findBreakTarget(labelText) {
ts.Debug.assert(blocks !== undefined);
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsLabeledBreakOrContinue(block) && block.labelText === labelText) {
return block.breakLabel;
}
else if (supportsUnlabeledBreak(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.breakLabel;
if (blockStack) {
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsLabeledBreakOrContinue(block) && block.labelText === labelText) {
return block.breakLabel;
}
else if (supportsUnlabeledBreak(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.breakLabel;
}
}
}
}
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledBreak(block)) {
return block.breakLabel;
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledBreak(block)) {
return block.breakLabel;
}
}
}
}
return 0;
}
function findContinueTarget(labelText) {
ts.Debug.assert(blocks !== undefined);
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.continueLabel;
if (blockStack) {
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.continueLabel;
}
}
}
}
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block)) {
return block.continueLabel;
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block)) {
return block.continueLabel;
}
}
}
}
@@ -49071,17 +49076,23 @@ var ts;
}
function addExportEqualsIfNeeded(statements, emitAsReturn) {
if (currentModuleInfo.exportEquals) {
if (emitAsReturn) {
var statement = ts.createReturn(currentModuleInfo.exportEquals.expression);
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 384 | 1536);
statements.push(statement);
}
else {
var statement = ts.createStatement(ts.createAssignment(ts.createPropertyAccess(ts.createIdentifier("module"), "exports"), currentModuleInfo.exportEquals.expression));
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 1536);
statements.push(statement);
var expressionResult = importCallExpressionVisitor(currentModuleInfo.exportEquals.expression);
if (expressionResult) {
if (expressionResult instanceof Array) {
return ts.Debug.fail("export= expression should never be replaced with multiple expressions!");
}
if (emitAsReturn) {
var statement = ts.createReturn(expressionResult);
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 384 | 1536);
statements.push(statement);
}
else {
var statement = ts.createStatement(ts.createAssignment(ts.createPropertyAccess(ts.createIdentifier("module"), "exports"), expressionResult));
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 1536);
statements.push(statement);
}
}
}
}
@@ -49415,7 +49426,7 @@ var ts;
return statements;
}
if (ts.hasModifier(decl, 1)) {
var exportName = ts.hasModifier(decl, 512) ? ts.createIdentifier("default") : decl.name;
var exportName = ts.hasModifier(decl, 512) ? ts.createIdentifier("default") : ts.getDeclarationName(decl);
statements = appendExportStatement(statements, exportName, ts.getLocalName(decl), decl);
}
if (decl.name) {
+141 -125
View File
@@ -1066,6 +1066,7 @@ var ts;
EmitFlags[EmitFlags["HasEndOfDeclarationMarker"] = 4194304] = "HasEndOfDeclarationMarker";
EmitFlags[EmitFlags["Iterator"] = 8388608] = "Iterator";
EmitFlags[EmitFlags["NoAsciiEscaping"] = 16777216] = "NoAsciiEscaping";
EmitFlags[EmitFlags["TypeScriptClassWrapper"] = 33554432] = "TypeScriptClassWrapper";
})(EmitFlags = ts.EmitFlags || (ts.EmitFlags = {}));
var ExternalEmitHelpers;
(function (ExternalEmitHelpers) {
@@ -4557,7 +4558,7 @@ var ts;
Convert_function_to_an_ES2015_class: diag(95001, ts.DiagnosticCategory.Message, "Convert_function_to_an_ES2015_class_95001", "Convert function to an ES2015 class"),
Convert_function_0_to_class: diag(95002, ts.DiagnosticCategory.Message, "Convert_function_0_to_class_95002", "Convert function '{0}' to class"),
Extract_function: diag(95003, ts.DiagnosticCategory.Message, "Extract_function_95003", "Extract function"),
Extract_function_into_0: diag(95004, ts.DiagnosticCategory.Message, "Extract_function_into_0_95004", "Extract function into '{0}'"),
Extract_function_into_0: diag(95004, ts.DiagnosticCategory.Message, "Extract_function_into_0_95004", "Extract function into {0}"),
};
})(ts || (ts = {}));
var ts;
@@ -7133,9 +7134,9 @@ var ts;
|| kind === 265;
}
ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment;
function nodeIsSynthesized(node) {
return ts.positionIsSynthesized(node.pos)
|| ts.positionIsSynthesized(node.end);
function nodeIsSynthesized(range) {
return ts.positionIsSynthesized(range.pos)
|| ts.positionIsSynthesized(range.end);
}
ts.nodeIsSynthesized = nodeIsSynthesized;
function getOriginalSourceFile(sourceFile) {
@@ -20010,7 +20011,10 @@ var ts;
}
return true;
}
if (usage.parent.kind === 246) {
if (usage.parent.kind === 246 || (usage.parent.kind === 243 && usage.parent.isExportEquals)) {
return true;
}
if (usage.kind === 243 && usage.isExportEquals) {
return true;
}
var container = ts.getEnclosingBlockScopeContainer(declaration);
@@ -24678,6 +24682,9 @@ var ts;
}
return signature.resolvedReturnType;
}
function isResolvingReturnTypeOfSignature(signature) {
return !signature.resolvedReturnType && findResolutionCycleStartIndex(signature, 3) >= 0;
}
function getRestTypeOfSignature(signature) {
if (signature.hasRestParameter) {
var type = getTypeOfSymbol(ts.lastOrUndefined(signature.parameters));
@@ -29785,7 +29792,7 @@ var ts;
return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl));
}
var signature = getContextualSignatureForFunctionLikeDeclaration(functionDecl);
if (signature) {
if (signature && !isResolvingReturnTypeOfSignature(signature)) {
return getReturnTypeOfSignature(signature);
}
return undefined;
@@ -32075,7 +32082,7 @@ var ts;
return result;
}
function isJavaScriptConstructor(node) {
if (ts.isInJavaScriptFile(node)) {
if (node && ts.isInJavaScriptFile(node)) {
if (ts.getJSDocClassTag(node))
return true;
var symbol = ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) ? getSymbolOfNode(node) :
@@ -32085,6 +32092,20 @@ var ts;
}
return false;
}
function getJavaScriptClassType(symbol) {
if (ts.isDeclarationOfFunctionOrClassExpression(symbol)) {
symbol = getSymbolOfNode(symbol.valueDeclaration.initializer);
}
if (isJavaScriptConstructor(symbol.valueDeclaration)) {
return getInferredClassType(symbol);
}
if (symbol.flags & 3) {
var valueType = getTypeOfSymbol(symbol);
if (valueType.symbol && !isInferredClassType(valueType) && isJavaScriptConstructor(valueType.symbol.valueDeclaration)) {
return getInferredClassType(valueType.symbol);
}
}
}
function getInferredClassType(symbol) {
var links = getSymbolLinks(symbol);
if (!links.inferredClassType) {
@@ -32113,13 +32134,11 @@ var ts;
var funcSymbol = node.expression.kind === 71 ?
getResolvedSymbol(node.expression) :
checkExpression(node.expression).symbol;
if (funcSymbol && ts.isDeclarationOfFunctionOrClassExpression(funcSymbol)) {
funcSymbol = getSymbolOfNode(funcSymbol.valueDeclaration.initializer);
var type = funcSymbol && getJavaScriptClassType(funcSymbol);
if (type) {
return type;
}
if (funcSymbol && funcSymbol.flags & 16 && (funcSymbol.members || ts.getJSDocClassTag(funcSymbol.valueDeclaration))) {
return getInferredClassType(funcSymbol);
}
else if (noImplicitAny) {
if (noImplicitAny) {
error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
}
return anyType;
@@ -34280,6 +34299,7 @@ var ts;
: 4;
case 229:
case 232:
case 240:
return 2 | 1;
case 237:
var result_3 = 0;
@@ -37452,6 +37472,14 @@ var ts;
return type.flags & 32768 && getSignaturesOfType(type, 0).length > 0;
}
function getTypeReferenceSerializationKind(typeName, location) {
typeName = ts.getParseTreeNode(typeName, ts.isEntityName);
if (!typeName)
return ts.TypeReferenceSerializationKind.Unknown;
if (location) {
location = ts.getParseTreeNode(location);
if (!location)
return ts.TypeReferenceSerializationKind.Unknown;
}
var valueSymbol = resolveEntityName(typeName, 107455, true, false, location);
var typeSymbol = resolveEntityName(typeName, 793064, true, false, location);
if (valueSymbol && valueSymbol === typeSymbol) {
@@ -40909,6 +40937,10 @@ var ts;
return createCall(createFunctionExpression(undefined, undefined, undefined, undefined, param ? [param] : [], undefined, createBlock(statements, true)), undefined, paramValue ? [paramValue] : []);
}
ts.createImmediatelyInvokedFunctionExpression = createImmediatelyInvokedFunctionExpression;
function createImmediatelyInvokedArrowFunction(statements, param, paramValue) {
return createCall(createArrowFunction(undefined, undefined, param ? [param] : [], undefined, undefined, createBlock(statements, true)), undefined, paramValue ? [paramValue] : []);
}
ts.createImmediatelyInvokedArrowFunction = createImmediatelyInvokedArrowFunction;
function createComma(left, right) {
return createBinary(left, 26, right);
}
@@ -41999,9 +42031,17 @@ var ts;
case 288: return ts.updatePartiallyEmittedExpression(outerExpression, expression);
}
}
function isIgnorableParen(node) {
return node.kind === 185
&& ts.nodeIsSynthesized(node)
&& ts.nodeIsSynthesized(ts.getSourceMapRange(node))
&& ts.nodeIsSynthesized(ts.getCommentRange(node))
&& !ts.some(ts.getSyntheticLeadingComments(node))
&& !ts.some(ts.getSyntheticTrailingComments(node));
}
function recreateOuterExpressions(outerExpression, innerExpression, kinds) {
if (kinds === void 0) { kinds = 7; }
if (outerExpression && isOuterExpression(outerExpression, kinds)) {
if (outerExpression && isOuterExpression(outerExpression, kinds) && !isIgnorableParen(outerExpression)) {
return updateOuterExpression(outerExpression, recreateOuterExpressions(outerExpression.expression, innerExpression));
}
return innerExpression;
@@ -43227,7 +43267,7 @@ var ts;
}
else {
var name = node.name;
if (!uniqueExports.get(ts.unescapeLeadingUnderscores(name.escapedText))) {
if (name && !uniqueExports.get(ts.unescapeLeadingUnderscores(name.escapedText))) {
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name);
uniqueExports.set(ts.unescapeLeadingUnderscores(name.escapedText), true);
exportedNames = ts.append(exportedNames, name);
@@ -43927,8 +43967,10 @@ var ts;
ts.setEmitFlags(statement, 1536 | 384);
statements.push(statement);
ts.addRange(statements, context.endLexicalEnvironment());
var iife = ts.createImmediatelyInvokedArrowFunction(statements);
ts.setEmitFlags(iife, 33554432);
var varStatement = ts.createVariableStatement(undefined, ts.createVariableDeclarationList([
ts.createVariableDeclaration(ts.getLocalName(node, false, false), undefined, ts.createImmediatelyInvokedFunctionExpression(statements))
ts.createVariableDeclaration(ts.getLocalName(node, false, false), undefined, iife)
]));
ts.setOriginalNode(varStatement, node);
ts.setCommentRange(varStatement, node);
@@ -44534,7 +44576,7 @@ var ts;
var name = ts.getMutableClone(node);
name.flags &= ~8;
name.original = undefined;
name.parent = currentScope;
name.parent = ts.getParseTreeNode(currentScope);
if (useFallback) {
return ts.createLogicalAnd(ts.createStrictInequality(ts.createTypeOf(name), ts.createLiteral("undefined")), name);
}
@@ -45626,7 +45668,7 @@ var ts;
chunkObject.push(ts.createPropertyAssignment(p.name, ts.visitNode(p.initializer, visitor, ts.isExpression)));
}
else {
chunkObject.push(e);
chunkObject.push(ts.visitNode(e, visitor, ts.isObjectLiteralElementLike));
}
}
}
@@ -46641,58 +46683,12 @@ var ts;
&& node.kind === 219
&& !node.expression;
}
function isClassLikeVariableStatement(node) {
if (!ts.isVariableStatement(node))
return false;
var variable = ts.singleOrUndefined(node.declarationList.declarations);
return variable
&& variable.initializer
&& ts.isIdentifier(variable.name)
&& (ts.isClassLike(variable.initializer)
|| (ts.isAssignmentExpression(variable.initializer)
&& ts.isIdentifier(variable.initializer.left)
&& ts.isClassLike(variable.initializer.right)));
}
function isTypeScriptClassWrapper(node) {
var call = ts.tryCast(node, ts.isCallExpression);
if (!call || ts.isParseTreeNode(call) ||
ts.some(call.typeArguments) ||
ts.some(call.arguments)) {
return false;
}
var func = ts.tryCast(ts.skipOuterExpressions(call.expression), ts.isFunctionExpression);
if (!func || ts.isParseTreeNode(func) ||
ts.some(func.typeParameters) ||
ts.some(func.parameters) ||
func.type ||
!func.body) {
return false;
}
var statements = func.body.statements;
if (statements.length < 2) {
return false;
}
var firstStatement = statements[0];
if (ts.isParseTreeNode(firstStatement) ||
!ts.isClassLike(firstStatement) &&
!isClassLikeVariableStatement(firstStatement)) {
return false;
}
var lastStatement = ts.elementAt(statements, -1);
var returnStatement = ts.tryCast(ts.isVariableStatement(lastStatement) ? ts.elementAt(statements, -2) : lastStatement, ts.isReturnStatement);
if (!returnStatement ||
!returnStatement.expression ||
!ts.isIdentifier(ts.skipOuterExpressions(returnStatement.expression))) {
return false;
}
return true;
}
function shouldVisitNode(node) {
return (node.transformFlags & 128) !== 0
|| convertedLoopState !== undefined
|| (hierarchyFacts & 4096 && (ts.isStatement(node) || (node.kind === 207)))
|| (ts.isIterationStatement(node, false) && shouldConvertIterationStatementBody(node))
|| isTypeScriptClassWrapper(node);
|| (ts.getEmitFlags(node) & 33554432) !== 0;
}
function visitor(node) {
if (shouldVisitNode(node)) {
@@ -48172,7 +48168,7 @@ var ts;
return ts.visitEachChild(node, visitor, context);
}
function visitCallExpression(node) {
if (isTypeScriptClassWrapper(node)) {
if (ts.getEmitFlags(node) & 33554432) {
return visitTypeScriptClassWrapper(node);
}
if (node.transformFlags & 64) {
@@ -48181,7 +48177,7 @@ var ts;
return ts.updateCall(node, ts.visitNode(node.expression, callExpressionVisitor, ts.isExpression), undefined, ts.visitNodes(node.arguments, visitor, ts.isExpression));
}
function visitTypeScriptClassWrapper(node) {
var body = ts.cast(ts.skipOuterExpressions(node.expression), ts.isFunctionExpression).body;
var body = ts.cast(ts.cast(ts.skipOuterExpressions(node.expression), ts.isArrowFunction).body, ts.isBlock);
var classStatements = ts.visitNodes(body.statements, visitor, ts.isStatement, 0, 1);
var remainingStatements = ts.visitNodes(body.statements, visitor, ts.isStatement, 1, body.statements.length - 1);
var varStatement = ts.cast(ts.firstOrUndefined(classStatements), ts.isVariableStatement);
@@ -49351,8 +49347,12 @@ var ts;
}
function transformAndEmitContinueStatement(node) {
var label = findContinueTarget(node.label ? ts.unescapeLeadingUnderscores(node.label.escapedText) : undefined);
ts.Debug.assert(label > 0, "Expected continue statment to point to a valid Label.");
emitBreak(label, node);
if (label > 0) {
emitBreak(label, node);
}
else {
emitStatement(node);
}
}
function visitContinueStatement(node) {
if (inStatementContainingYield) {
@@ -49365,8 +49365,12 @@ var ts;
}
function transformAndEmitBreakStatement(node) {
var label = findBreakTarget(node.label ? ts.unescapeLeadingUnderscores(node.label.escapedText) : undefined);
ts.Debug.assert(label > 0, "Expected break statment to point to a valid Label.");
emitBreak(label, node);
if (label > 0) {
emitBreak(label, node);
}
else {
emitStatement(node);
}
}
function visitBreakStatement(node) {
if (inStatementContainingYield) {
@@ -49790,43 +49794,45 @@ var ts;
return false;
}
function findBreakTarget(labelText) {
ts.Debug.assert(blocks !== undefined);
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsLabeledBreakOrContinue(block) && block.labelText === labelText) {
return block.breakLabel;
}
else if (supportsUnlabeledBreak(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.breakLabel;
if (blockStack) {
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsLabeledBreakOrContinue(block) && block.labelText === labelText) {
return block.breakLabel;
}
else if (supportsUnlabeledBreak(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.breakLabel;
}
}
}
}
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledBreak(block)) {
return block.breakLabel;
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledBreak(block)) {
return block.breakLabel;
}
}
}
}
return 0;
}
function findContinueTarget(labelText) {
ts.Debug.assert(blocks !== undefined);
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.continueLabel;
if (blockStack) {
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.continueLabel;
}
}
}
}
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block)) {
return block.continueLabel;
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block)) {
return block.continueLabel;
}
}
}
}
@@ -50450,17 +50456,23 @@ var ts;
}
function addExportEqualsIfNeeded(statements, emitAsReturn) {
if (currentModuleInfo.exportEquals) {
if (emitAsReturn) {
var statement = ts.createReturn(currentModuleInfo.exportEquals.expression);
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 384 | 1536);
statements.push(statement);
}
else {
var statement = ts.createStatement(ts.createAssignment(ts.createPropertyAccess(ts.createIdentifier("module"), "exports"), currentModuleInfo.exportEquals.expression));
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 1536);
statements.push(statement);
var expressionResult = importCallExpressionVisitor(currentModuleInfo.exportEquals.expression);
if (expressionResult) {
if (expressionResult instanceof Array) {
return ts.Debug.fail("export= expression should never be replaced with multiple expressions!");
}
if (emitAsReturn) {
var statement = ts.createReturn(expressionResult);
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 384 | 1536);
statements.push(statement);
}
else {
var statement = ts.createStatement(ts.createAssignment(ts.createPropertyAccess(ts.createIdentifier("module"), "exports"), expressionResult));
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 1536);
statements.push(statement);
}
}
}
}
@@ -50794,7 +50806,7 @@ var ts;
return statements;
}
if (ts.hasModifier(decl, 1)) {
var exportName = ts.hasModifier(decl, 512) ? ts.createIdentifier("default") : decl.name;
var exportName = ts.hasModifier(decl, 512) ? ts.createIdentifier("default") : ts.getDeclarationName(decl);
statements = appendExportStatement(statements, exportName, ts.getLocalName(decl), decl);
}
if (decl.name) {
@@ -74613,12 +74625,7 @@ var ts;
if (errors) {
return { errors: errors };
}
var range = ts.isStatement(start)
? [start]
: start.parent && start.parent.kind === 210
? [start.parent]
: start;
return { targetRange: { range: range, facts: rangeFacts, declarations: declarations } };
return { targetRange: { range: getStatementOrExpressionRange(start), facts: rangeFacts, declarations: declarations } };
}
function createErrorResult(sourceFile, start, length, message) {
return { errors: [ts.createFileDiagnostic(sourceFile, start, length, message)] };
@@ -74803,6 +74810,15 @@ var ts;
}
}
extractMethod_1.getRangeToExtract = getRangeToExtract;
function getStatementOrExpressionRange(node) {
if (ts.isStatement(node)) {
return [node];
}
else if (ts.isPartOfExpression(node)) {
return ts.isExpressionStatement(node.parent) ? [node.parent] : node;
}
return undefined;
}
function isValidExtractionTarget(node) {
return (node.kind === 228) || ts.isSourceFile(node) || isModuleBlock(node) || ts.isClassLike(node);
}
@@ -74871,32 +74887,32 @@ var ts;
return "constructor";
case 186:
return scope.name
? "function expression " + scope.name.getText()
? "function expression " + scope.name.text
: "anonymous function expression";
case 228:
return "function " + scope.name.getText();
return "function '" + scope.name.text + "'";
case 187:
return "arrow function";
case 151:
return "method " + scope.name.getText();
return "method '" + scope.name.getText();
case 153:
return "get " + scope.name.getText();
return "'get " + scope.name.getText() + "'";
case 154:
return "set " + scope.name.getText();
return "'set " + scope.name.getText() + "'";
}
}
else if (isModuleBlock(scope)) {
return "namespace " + scope.parent.name.getText();
return "namespace '" + scope.parent.name.getText() + "'";
}
else if (ts.isClassLike(scope)) {
return scope.kind === 229
? "class " + scope.name.text
? "class '" + scope.name.text + "'"
: scope.name.text
? "class expression " + scope.name.text
? "class expression '" + scope.name.text + "'"
: "anonymous class expression";
}
else if (ts.isSourceFile(scope)) {
return "file '" + scope.fileName + "'";
return scope.externalModuleIndicator ? "module scope" : "global scope";
}
else {
return "unknown";
+2
View File
@@ -2996,6 +2996,8 @@ declare namespace ts {
function updateBundle(node: Bundle, sourceFiles: SourceFile[]): Bundle;
function createImmediatelyInvokedFunctionExpression(statements: Statement[]): CallExpression;
function createImmediatelyInvokedFunctionExpression(statements: Statement[], param: ParameterDeclaration, paramValue: Expression): CallExpression;
function createImmediatelyInvokedArrowFunction(statements: Statement[]): CallExpression;
function createImmediatelyInvokedArrowFunction(statements: Statement[], param: ParameterDeclaration, paramValue: Expression): CallExpression;
function createComma(left: Expression, right: Expression): Expression;
function createLessThan(left: Expression, right: Expression): Expression;
function createAssignment(left: ObjectLiteralExpression | ArrayLiteralExpression, right: Expression): DestructuringAssignment;
+141 -125
View File
@@ -1066,6 +1066,7 @@ var ts;
EmitFlags[EmitFlags["HasEndOfDeclarationMarker"] = 4194304] = "HasEndOfDeclarationMarker";
EmitFlags[EmitFlags["Iterator"] = 8388608] = "Iterator";
EmitFlags[EmitFlags["NoAsciiEscaping"] = 16777216] = "NoAsciiEscaping";
EmitFlags[EmitFlags["TypeScriptClassWrapper"] = 33554432] = "TypeScriptClassWrapper";
})(EmitFlags = ts.EmitFlags || (ts.EmitFlags = {}));
var ExternalEmitHelpers;
(function (ExternalEmitHelpers) {
@@ -4557,7 +4558,7 @@ var ts;
Convert_function_to_an_ES2015_class: diag(95001, ts.DiagnosticCategory.Message, "Convert_function_to_an_ES2015_class_95001", "Convert function to an ES2015 class"),
Convert_function_0_to_class: diag(95002, ts.DiagnosticCategory.Message, "Convert_function_0_to_class_95002", "Convert function '{0}' to class"),
Extract_function: diag(95003, ts.DiagnosticCategory.Message, "Extract_function_95003", "Extract function"),
Extract_function_into_0: diag(95004, ts.DiagnosticCategory.Message, "Extract_function_into_0_95004", "Extract function into '{0}'"),
Extract_function_into_0: diag(95004, ts.DiagnosticCategory.Message, "Extract_function_into_0_95004", "Extract function into {0}"),
};
})(ts || (ts = {}));
var ts;
@@ -6330,9 +6331,9 @@ var ts;
|| kind === 265;
}
ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment;
function nodeIsSynthesized(node) {
return ts.positionIsSynthesized(node.pos)
|| ts.positionIsSynthesized(node.end);
function nodeIsSynthesized(range) {
return ts.positionIsSynthesized(range.pos)
|| ts.positionIsSynthesized(range.end);
}
ts.nodeIsSynthesized = nodeIsSynthesized;
function getOriginalSourceFile(sourceFile) {
@@ -21716,7 +21717,10 @@ var ts;
}
return true;
}
if (usage.parent.kind === 246) {
if (usage.parent.kind === 246 || (usage.parent.kind === 243 && usage.parent.isExportEquals)) {
return true;
}
if (usage.kind === 243 && usage.isExportEquals) {
return true;
}
var container = ts.getEnclosingBlockScopeContainer(declaration);
@@ -26384,6 +26388,9 @@ var ts;
}
return signature.resolvedReturnType;
}
function isResolvingReturnTypeOfSignature(signature) {
return !signature.resolvedReturnType && findResolutionCycleStartIndex(signature, 3) >= 0;
}
function getRestTypeOfSignature(signature) {
if (signature.hasRestParameter) {
var type = getTypeOfSymbol(ts.lastOrUndefined(signature.parameters));
@@ -31491,7 +31498,7 @@ var ts;
return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl));
}
var signature = getContextualSignatureForFunctionLikeDeclaration(functionDecl);
if (signature) {
if (signature && !isResolvingReturnTypeOfSignature(signature)) {
return getReturnTypeOfSignature(signature);
}
return undefined;
@@ -33781,7 +33788,7 @@ var ts;
return result;
}
function isJavaScriptConstructor(node) {
if (ts.isInJavaScriptFile(node)) {
if (node && ts.isInJavaScriptFile(node)) {
if (ts.getJSDocClassTag(node))
return true;
var symbol = ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) ? getSymbolOfNode(node) :
@@ -33791,6 +33798,20 @@ var ts;
}
return false;
}
function getJavaScriptClassType(symbol) {
if (ts.isDeclarationOfFunctionOrClassExpression(symbol)) {
symbol = getSymbolOfNode(symbol.valueDeclaration.initializer);
}
if (isJavaScriptConstructor(symbol.valueDeclaration)) {
return getInferredClassType(symbol);
}
if (symbol.flags & 3) {
var valueType = getTypeOfSymbol(symbol);
if (valueType.symbol && !isInferredClassType(valueType) && isJavaScriptConstructor(valueType.symbol.valueDeclaration)) {
return getInferredClassType(valueType.symbol);
}
}
}
function getInferredClassType(symbol) {
var links = getSymbolLinks(symbol);
if (!links.inferredClassType) {
@@ -33819,13 +33840,11 @@ var ts;
var funcSymbol = node.expression.kind === 71 ?
getResolvedSymbol(node.expression) :
checkExpression(node.expression).symbol;
if (funcSymbol && ts.isDeclarationOfFunctionOrClassExpression(funcSymbol)) {
funcSymbol = getSymbolOfNode(funcSymbol.valueDeclaration.initializer);
var type = funcSymbol && getJavaScriptClassType(funcSymbol);
if (type) {
return type;
}
if (funcSymbol && funcSymbol.flags & 16 && (funcSymbol.members || ts.getJSDocClassTag(funcSymbol.valueDeclaration))) {
return getInferredClassType(funcSymbol);
}
else if (noImplicitAny) {
if (noImplicitAny) {
error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
}
return anyType;
@@ -35986,6 +36005,7 @@ var ts;
: 4;
case 229:
case 232:
case 240:
return 2 | 1;
case 237:
var result_3 = 0;
@@ -39158,6 +39178,14 @@ var ts;
return type.flags & 32768 && getSignaturesOfType(type, 0).length > 0;
}
function getTypeReferenceSerializationKind(typeName, location) {
typeName = ts.getParseTreeNode(typeName, ts.isEntityName);
if (!typeName)
return ts.TypeReferenceSerializationKind.Unknown;
if (location) {
location = ts.getParseTreeNode(location);
if (!location)
return ts.TypeReferenceSerializationKind.Unknown;
}
var valueSymbol = resolveEntityName(typeName, 107455, true, false, location);
var typeSymbol = resolveEntityName(typeName, 793064, true, false, location);
if (valueSymbol && valueSymbol === typeSymbol) {
@@ -42615,6 +42643,10 @@ var ts;
return createCall(createFunctionExpression(undefined, undefined, undefined, undefined, param ? [param] : [], undefined, createBlock(statements, true)), undefined, paramValue ? [paramValue] : []);
}
ts.createImmediatelyInvokedFunctionExpression = createImmediatelyInvokedFunctionExpression;
function createImmediatelyInvokedArrowFunction(statements, param, paramValue) {
return createCall(createArrowFunction(undefined, undefined, param ? [param] : [], undefined, undefined, createBlock(statements, true)), undefined, paramValue ? [paramValue] : []);
}
ts.createImmediatelyInvokedArrowFunction = createImmediatelyInvokedArrowFunction;
function createComma(left, right) {
return createBinary(left, 26, right);
}
@@ -43705,9 +43737,17 @@ var ts;
case 288: return ts.updatePartiallyEmittedExpression(outerExpression, expression);
}
}
function isIgnorableParen(node) {
return node.kind === 185
&& ts.nodeIsSynthesized(node)
&& ts.nodeIsSynthesized(ts.getSourceMapRange(node))
&& ts.nodeIsSynthesized(ts.getCommentRange(node))
&& !ts.some(ts.getSyntheticLeadingComments(node))
&& !ts.some(ts.getSyntheticTrailingComments(node));
}
function recreateOuterExpressions(outerExpression, innerExpression, kinds) {
if (kinds === void 0) { kinds = 7; }
if (outerExpression && isOuterExpression(outerExpression, kinds)) {
if (outerExpression && isOuterExpression(outerExpression, kinds) && !isIgnorableParen(outerExpression)) {
return updateOuterExpression(outerExpression, recreateOuterExpressions(outerExpression.expression, innerExpression));
}
return innerExpression;
@@ -44933,7 +44973,7 @@ var ts;
}
else {
var name = node.name;
if (!uniqueExports.get(ts.unescapeLeadingUnderscores(name.escapedText))) {
if (name && !uniqueExports.get(ts.unescapeLeadingUnderscores(name.escapedText))) {
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name);
uniqueExports.set(ts.unescapeLeadingUnderscores(name.escapedText), true);
exportedNames = ts.append(exportedNames, name);
@@ -45633,8 +45673,10 @@ var ts;
ts.setEmitFlags(statement, 1536 | 384);
statements.push(statement);
ts.addRange(statements, context.endLexicalEnvironment());
var iife = ts.createImmediatelyInvokedArrowFunction(statements);
ts.setEmitFlags(iife, 33554432);
var varStatement = ts.createVariableStatement(undefined, ts.createVariableDeclarationList([
ts.createVariableDeclaration(ts.getLocalName(node, false, false), undefined, ts.createImmediatelyInvokedFunctionExpression(statements))
ts.createVariableDeclaration(ts.getLocalName(node, false, false), undefined, iife)
]));
ts.setOriginalNode(varStatement, node);
ts.setCommentRange(varStatement, node);
@@ -46240,7 +46282,7 @@ var ts;
var name = ts.getMutableClone(node);
name.flags &= ~8;
name.original = undefined;
name.parent = currentScope;
name.parent = ts.getParseTreeNode(currentScope);
if (useFallback) {
return ts.createLogicalAnd(ts.createStrictInequality(ts.createTypeOf(name), ts.createLiteral("undefined")), name);
}
@@ -47332,7 +47374,7 @@ var ts;
chunkObject.push(ts.createPropertyAssignment(p.name, ts.visitNode(p.initializer, visitor, ts.isExpression)));
}
else {
chunkObject.push(e);
chunkObject.push(ts.visitNode(e, visitor, ts.isObjectLiteralElementLike));
}
}
}
@@ -48347,58 +48389,12 @@ var ts;
&& node.kind === 219
&& !node.expression;
}
function isClassLikeVariableStatement(node) {
if (!ts.isVariableStatement(node))
return false;
var variable = ts.singleOrUndefined(node.declarationList.declarations);
return variable
&& variable.initializer
&& ts.isIdentifier(variable.name)
&& (ts.isClassLike(variable.initializer)
|| (ts.isAssignmentExpression(variable.initializer)
&& ts.isIdentifier(variable.initializer.left)
&& ts.isClassLike(variable.initializer.right)));
}
function isTypeScriptClassWrapper(node) {
var call = ts.tryCast(node, ts.isCallExpression);
if (!call || ts.isParseTreeNode(call) ||
ts.some(call.typeArguments) ||
ts.some(call.arguments)) {
return false;
}
var func = ts.tryCast(ts.skipOuterExpressions(call.expression), ts.isFunctionExpression);
if (!func || ts.isParseTreeNode(func) ||
ts.some(func.typeParameters) ||
ts.some(func.parameters) ||
func.type ||
!func.body) {
return false;
}
var statements = func.body.statements;
if (statements.length < 2) {
return false;
}
var firstStatement = statements[0];
if (ts.isParseTreeNode(firstStatement) ||
!ts.isClassLike(firstStatement) &&
!isClassLikeVariableStatement(firstStatement)) {
return false;
}
var lastStatement = ts.elementAt(statements, -1);
var returnStatement = ts.tryCast(ts.isVariableStatement(lastStatement) ? ts.elementAt(statements, -2) : lastStatement, ts.isReturnStatement);
if (!returnStatement ||
!returnStatement.expression ||
!ts.isIdentifier(ts.skipOuterExpressions(returnStatement.expression))) {
return false;
}
return true;
}
function shouldVisitNode(node) {
return (node.transformFlags & 128) !== 0
|| convertedLoopState !== undefined
|| (hierarchyFacts & 4096 && (ts.isStatement(node) || (node.kind === 207)))
|| (ts.isIterationStatement(node, false) && shouldConvertIterationStatementBody(node))
|| isTypeScriptClassWrapper(node);
|| (ts.getEmitFlags(node) & 33554432) !== 0;
}
function visitor(node) {
if (shouldVisitNode(node)) {
@@ -49878,7 +49874,7 @@ var ts;
return ts.visitEachChild(node, visitor, context);
}
function visitCallExpression(node) {
if (isTypeScriptClassWrapper(node)) {
if (ts.getEmitFlags(node) & 33554432) {
return visitTypeScriptClassWrapper(node);
}
if (node.transformFlags & 64) {
@@ -49887,7 +49883,7 @@ var ts;
return ts.updateCall(node, ts.visitNode(node.expression, callExpressionVisitor, ts.isExpression), undefined, ts.visitNodes(node.arguments, visitor, ts.isExpression));
}
function visitTypeScriptClassWrapper(node) {
var body = ts.cast(ts.skipOuterExpressions(node.expression), ts.isFunctionExpression).body;
var body = ts.cast(ts.cast(ts.skipOuterExpressions(node.expression), ts.isArrowFunction).body, ts.isBlock);
var classStatements = ts.visitNodes(body.statements, visitor, ts.isStatement, 0, 1);
var remainingStatements = ts.visitNodes(body.statements, visitor, ts.isStatement, 1, body.statements.length - 1);
var varStatement = ts.cast(ts.firstOrUndefined(classStatements), ts.isVariableStatement);
@@ -51057,8 +51053,12 @@ var ts;
}
function transformAndEmitContinueStatement(node) {
var label = findContinueTarget(node.label ? ts.unescapeLeadingUnderscores(node.label.escapedText) : undefined);
ts.Debug.assert(label > 0, "Expected continue statment to point to a valid Label.");
emitBreak(label, node);
if (label > 0) {
emitBreak(label, node);
}
else {
emitStatement(node);
}
}
function visitContinueStatement(node) {
if (inStatementContainingYield) {
@@ -51071,8 +51071,12 @@ var ts;
}
function transformAndEmitBreakStatement(node) {
var label = findBreakTarget(node.label ? ts.unescapeLeadingUnderscores(node.label.escapedText) : undefined);
ts.Debug.assert(label > 0, "Expected break statment to point to a valid Label.");
emitBreak(label, node);
if (label > 0) {
emitBreak(label, node);
}
else {
emitStatement(node);
}
}
function visitBreakStatement(node) {
if (inStatementContainingYield) {
@@ -51496,43 +51500,45 @@ var ts;
return false;
}
function findBreakTarget(labelText) {
ts.Debug.assert(blocks !== undefined);
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsLabeledBreakOrContinue(block) && block.labelText === labelText) {
return block.breakLabel;
}
else if (supportsUnlabeledBreak(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.breakLabel;
if (blockStack) {
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsLabeledBreakOrContinue(block) && block.labelText === labelText) {
return block.breakLabel;
}
else if (supportsUnlabeledBreak(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.breakLabel;
}
}
}
}
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledBreak(block)) {
return block.breakLabel;
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledBreak(block)) {
return block.breakLabel;
}
}
}
}
return 0;
}
function findContinueTarget(labelText) {
ts.Debug.assert(blocks !== undefined);
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.continueLabel;
if (blockStack) {
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.continueLabel;
}
}
}
}
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block)) {
return block.continueLabel;
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block)) {
return block.continueLabel;
}
}
}
}
@@ -52156,17 +52162,23 @@ var ts;
}
function addExportEqualsIfNeeded(statements, emitAsReturn) {
if (currentModuleInfo.exportEquals) {
if (emitAsReturn) {
var statement = ts.createReturn(currentModuleInfo.exportEquals.expression);
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 384 | 1536);
statements.push(statement);
}
else {
var statement = ts.createStatement(ts.createAssignment(ts.createPropertyAccess(ts.createIdentifier("module"), "exports"), currentModuleInfo.exportEquals.expression));
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 1536);
statements.push(statement);
var expressionResult = importCallExpressionVisitor(currentModuleInfo.exportEquals.expression);
if (expressionResult) {
if (expressionResult instanceof Array) {
return ts.Debug.fail("export= expression should never be replaced with multiple expressions!");
}
if (emitAsReturn) {
var statement = ts.createReturn(expressionResult);
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 384 | 1536);
statements.push(statement);
}
else {
var statement = ts.createStatement(ts.createAssignment(ts.createPropertyAccess(ts.createIdentifier("module"), "exports"), expressionResult));
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 1536);
statements.push(statement);
}
}
}
}
@@ -52500,7 +52512,7 @@ var ts;
return statements;
}
if (ts.hasModifier(decl, 1)) {
var exportName = ts.hasModifier(decl, 512) ? ts.createIdentifier("default") : decl.name;
var exportName = ts.hasModifier(decl, 512) ? ts.createIdentifier("default") : ts.getDeclarationName(decl);
statements = appendExportStatement(statements, exportName, ts.getLocalName(decl), decl);
}
if (decl.name) {
@@ -74613,12 +74625,7 @@ var ts;
if (errors) {
return { errors: errors };
}
var range = ts.isStatement(start)
? [start]
: start.parent && start.parent.kind === 210
? [start.parent]
: start;
return { targetRange: { range: range, facts: rangeFacts, declarations: declarations } };
return { targetRange: { range: getStatementOrExpressionRange(start), facts: rangeFacts, declarations: declarations } };
}
function createErrorResult(sourceFile, start, length, message) {
return { errors: [ts.createFileDiagnostic(sourceFile, start, length, message)] };
@@ -74803,6 +74810,15 @@ var ts;
}
}
extractMethod_1.getRangeToExtract = getRangeToExtract;
function getStatementOrExpressionRange(node) {
if (ts.isStatement(node)) {
return [node];
}
else if (ts.isPartOfExpression(node)) {
return ts.isExpressionStatement(node.parent) ? [node.parent] : node;
}
return undefined;
}
function isValidExtractionTarget(node) {
return (node.kind === 228) || ts.isSourceFile(node) || isModuleBlock(node) || ts.isClassLike(node);
}
@@ -74871,32 +74887,32 @@ var ts;
return "constructor";
case 186:
return scope.name
? "function expression " + scope.name.getText()
? "function expression " + scope.name.text
: "anonymous function expression";
case 228:
return "function " + scope.name.getText();
return "function '" + scope.name.text + "'";
case 187:
return "arrow function";
case 151:
return "method " + scope.name.getText();
return "method '" + scope.name.getText();
case 153:
return "get " + scope.name.getText();
return "'get " + scope.name.getText() + "'";
case 154:
return "set " + scope.name.getText();
return "'set " + scope.name.getText() + "'";
}
}
else if (isModuleBlock(scope)) {
return "namespace " + scope.parent.name.getText();
return "namespace '" + scope.parent.name.getText() + "'";
}
else if (ts.isClassLike(scope)) {
return scope.kind === 229
? "class " + scope.name.text
? "class '" + scope.name.text + "'"
: scope.name.text
? "class expression " + scope.name.text
? "class expression '" + scope.name.text + "'"
: "anonymous class expression";
}
else if (ts.isSourceFile(scope)) {
return "file '" + scope.fileName + "'";
return scope.externalModuleIndicator ? "module scope" : "global scope";
}
else {
return "unknown";
+2
View File
@@ -3388,6 +3388,8 @@ declare namespace ts {
function updateBundle(node: Bundle, sourceFiles: SourceFile[]): Bundle;
function createImmediatelyInvokedFunctionExpression(statements: Statement[]): CallExpression;
function createImmediatelyInvokedFunctionExpression(statements: Statement[], param: ParameterDeclaration, paramValue: Expression): CallExpression;
function createImmediatelyInvokedArrowFunction(statements: Statement[]): CallExpression;
function createImmediatelyInvokedArrowFunction(statements: Statement[], param: ParameterDeclaration, paramValue: Expression): CallExpression;
function createComma(left: Expression, right: Expression): Expression;
function createLessThan(left: Expression, right: Expression): Expression;
function createAssignment(left: ObjectLiteralExpression | ArrayLiteralExpression, right: Expression): DestructuringAssignment;
+172 -129
View File
@@ -1201,6 +1201,7 @@ var ts;
EmitFlags[EmitFlags["HasEndOfDeclarationMarker"] = 4194304] = "HasEndOfDeclarationMarker";
EmitFlags[EmitFlags["Iterator"] = 8388608] = "Iterator";
EmitFlags[EmitFlags["NoAsciiEscaping"] = 16777216] = "NoAsciiEscaping";
/*@internal*/ EmitFlags[EmitFlags["TypeScriptClassWrapper"] = 33554432] = "TypeScriptClassWrapper";
})(EmitFlags = ts.EmitFlags || (ts.EmitFlags = {}));
/**
* Used by the checker, this enum keeps track of external emit helpers that should be type
@@ -5080,7 +5081,7 @@ var ts;
Convert_function_to_an_ES2015_class: diag(95001, ts.DiagnosticCategory.Message, "Convert_function_to_an_ES2015_class_95001", "Convert function to an ES2015 class"),
Convert_function_0_to_class: diag(95002, ts.DiagnosticCategory.Message, "Convert_function_0_to_class_95002", "Convert function '{0}' to class"),
Extract_function: diag(95003, ts.DiagnosticCategory.Message, "Extract_function_95003", "Extract function"),
Extract_function_into_0: diag(95004, ts.DiagnosticCategory.Message, "Extract_function_into_0_95004", "Extract function into '{0}'"),
Extract_function_into_0: diag(95004, ts.DiagnosticCategory.Message, "Extract_function_into_0_95004", "Extract function into {0}"),
};
})(ts || (ts = {}));
/// <reference path="core.ts"/>
@@ -8844,9 +8845,9 @@ var ts;
|| kind === 265 /* SourceFile */;
}
ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment;
function nodeIsSynthesized(node) {
return ts.positionIsSynthesized(node.pos)
|| ts.positionIsSynthesized(node.end);
function nodeIsSynthesized(range) {
return ts.positionIsSynthesized(range.pos)
|| ts.positionIsSynthesized(range.end);
}
ts.nodeIsSynthesized = nodeIsSynthesized;
function getOriginalSourceFile(sourceFile) {
@@ -23319,12 +23320,17 @@ var ts;
// 2. inside a function
// 3. inside an instance property initializer, a reference to a non-instance property
// 4. inside a static property initializer, a reference to a static method in the same class
// 5. inside a TS export= declaration (since we will move the export statement during emit to avoid TDZ)
// or if usage is in a type context:
// 1. inside a type query (typeof in type position)
if (usage.parent.kind === 246 /* ExportSpecifier */) {
if (usage.parent.kind === 246 /* ExportSpecifier */ || (usage.parent.kind === 243 /* ExportAssignment */ && usage.parent.isExportEquals)) {
// export specifiers do not use the variable, they only make it available for use
return true;
}
// When resolving symbols for exports, the `usage` location passed in can be the export site directly
if (usage.kind === 243 /* ExportAssignment */ && usage.isExportEquals) {
return true;
}
var container = ts.getEnclosingBlockScopeContainer(declaration);
return isInTypeQuery(usage) || isUsedInFunctionOrInstanceProperty(usage, declaration, container);
function isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration, usage) {
@@ -28615,6 +28621,9 @@ var ts;
}
return signature.resolvedReturnType;
}
function isResolvingReturnTypeOfSignature(signature) {
return !signature.resolvedReturnType && findResolutionCycleStartIndex(signature, 3 /* ResolvedReturnType */) >= 0;
}
function getRestTypeOfSignature(signature) {
if (signature.hasRestParameter) {
var type = getTypeOfSymbol(ts.lastOrUndefined(signature.parameters));
@@ -34496,7 +34505,7 @@ var ts;
// Otherwise, if the containing function is contextually typed by a function type with exactly one call signature
// and that call signature is non-generic, return statements are contextually typed by the return type of the signature
var signature = getContextualSignatureForFunctionLikeDeclaration(functionDecl);
if (signature) {
if (signature && !isResolvingReturnTypeOfSignature(signature)) {
return getReturnTypeOfSignature(signature);
}
return undefined;
@@ -37549,7 +37558,7 @@ var ts;
* file.
*/
function isJavaScriptConstructor(node) {
if (ts.isInJavaScriptFile(node)) {
if (node && ts.isInJavaScriptFile(node)) {
// If the node has a @class tag, treat it like a constructor.
if (ts.getJSDocClassTag(node))
return true;
@@ -37561,6 +37570,20 @@ var ts;
}
return false;
}
function getJavaScriptClassType(symbol) {
if (ts.isDeclarationOfFunctionOrClassExpression(symbol)) {
symbol = getSymbolOfNode(symbol.valueDeclaration.initializer);
}
if (isJavaScriptConstructor(symbol.valueDeclaration)) {
return getInferredClassType(symbol);
}
if (symbol.flags & 3 /* Variable */) {
var valueType = getTypeOfSymbol(symbol);
if (valueType.symbol && !isInferredClassType(valueType) && isJavaScriptConstructor(valueType.symbol.valueDeclaration)) {
return getInferredClassType(valueType.symbol);
}
}
}
function getInferredClassType(symbol) {
var links = getSymbolLinks(symbol);
if (!links.inferredClassType) {
@@ -37600,13 +37623,11 @@ var ts;
var funcSymbol = node.expression.kind === 71 /* Identifier */ ?
getResolvedSymbol(node.expression) :
checkExpression(node.expression).symbol;
if (funcSymbol && ts.isDeclarationOfFunctionOrClassExpression(funcSymbol)) {
funcSymbol = getSymbolOfNode(funcSymbol.valueDeclaration.initializer);
var type = funcSymbol && getJavaScriptClassType(funcSymbol);
if (type) {
return type;
}
if (funcSymbol && funcSymbol.flags & 16 /* Function */ && (funcSymbol.members || ts.getJSDocClassTag(funcSymbol.valueDeclaration))) {
return getInferredClassType(funcSymbol);
}
else if (noImplicitAny) {
if (noImplicitAny) {
error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
}
return anyType;
@@ -40064,6 +40085,8 @@ var ts;
: 4 /* ExportNamespace */;
case 229 /* ClassDeclaration */:
case 232 /* EnumDeclaration */:
// A NamespaceImport declares an Alias, which is allowed to merge with other values within the module
case 240 /* NamespaceImport */:
return 2 /* ExportType */ | 1 /* ExportValue */;
case 237 /* ImportEqualsDeclaration */:
var result_3 = 0 /* None */;
@@ -43921,6 +43944,15 @@ var ts;
return type.flags & 32768 /* Object */ && getSignaturesOfType(type, 0 /* Call */).length > 0;
}
function getTypeReferenceSerializationKind(typeName, location) {
// ensure both `typeName` and `location` are parse tree nodes.
typeName = ts.getParseTreeNode(typeName, ts.isEntityName);
if (!typeName)
return ts.TypeReferenceSerializationKind.Unknown;
if (location) {
location = ts.getParseTreeNode(location);
if (!location)
return ts.TypeReferenceSerializationKind.Unknown;
}
// Resolve the symbol as a value to ensure the type can be reached at runtime during emit.
var valueSymbol = resolveEntityName(typeName, 107455 /* Value */, /*ignoreErrors*/ true, /*dontResolveAlias*/ false, location);
// Resolve the symbol as a type so that we can provide a more useful hint for the type serializer.
@@ -47563,6 +47595,17 @@ var ts;
/*argumentsArray*/ paramValue ? [paramValue] : []);
}
ts.createImmediatelyInvokedFunctionExpression = createImmediatelyInvokedFunctionExpression;
function createImmediatelyInvokedArrowFunction(statements, param, paramValue) {
return createCall(createArrowFunction(
/*modifiers*/ undefined,
/*typeParameters*/ undefined,
/*parameters*/ param ? [param] : [],
/*type*/ undefined,
/*equalsGreaterThanToken*/ undefined, createBlock(statements, /*multiLine*/ true)),
/*typeArguments*/ undefined,
/*argumentsArray*/ paramValue ? [paramValue] : []);
}
ts.createImmediatelyInvokedArrowFunction = createImmediatelyInvokedArrowFunction;
function createComma(left, right) {
return createBinary(left, 26 /* CommaToken */, right);
}
@@ -48963,9 +49006,31 @@ var ts;
case 288 /* PartiallyEmittedExpression */: return ts.updatePartiallyEmittedExpression(outerExpression, expression);
}
}
/**
* Determines whether a node is a parenthesized expression that can be ignored when recreating outer expressions.
*
* A parenthesized expression can be ignored when all of the following are true:
*
* - It's `pos` and `end` are not -1
* - It does not have a custom source map range
* - It does not have a custom comment range
* - It does not have synthetic leading or trailing comments
*
* If an outermost parenthesized expression is ignored, but the containing expression requires a parentheses around
* the expression to maintain precedence, a new parenthesized expression should be created automatically when
* the containing expression is created/updated.
*/
function isIgnorableParen(node) {
return node.kind === 185 /* ParenthesizedExpression */
&& ts.nodeIsSynthesized(node)
&& ts.nodeIsSynthesized(ts.getSourceMapRange(node))
&& ts.nodeIsSynthesized(ts.getCommentRange(node))
&& !ts.some(ts.getSyntheticLeadingComments(node))
&& !ts.some(ts.getSyntheticTrailingComments(node));
}
function recreateOuterExpressions(outerExpression, innerExpression, kinds) {
if (kinds === void 0) { kinds = 7 /* All */; }
if (outerExpression && isOuterExpression(outerExpression, kinds)) {
if (outerExpression && isOuterExpression(outerExpression, kinds) && !isIgnorableParen(outerExpression)) {
return updateOuterExpression(outerExpression, recreateOuterExpressions(outerExpression.expression, innerExpression));
}
return innerExpression;
@@ -50417,7 +50482,7 @@ var ts;
else {
// export class x { }
var name = node.name;
if (!uniqueExports.get(ts.unescapeLeadingUnderscores(name.escapedText))) {
if (name && !uniqueExports.get(ts.unescapeLeadingUnderscores(name.escapedText))) {
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name);
uniqueExports.set(ts.unescapeLeadingUnderscores(name.escapedText), true);
exportedNames = ts.append(exportedNames, name);
@@ -51435,10 +51500,12 @@ var ts;
ts.setEmitFlags(statement, 1536 /* NoComments */ | 384 /* NoTokenSourceMaps */);
statements.push(statement);
ts.addRange(statements, context.endLexicalEnvironment());
var iife = ts.createImmediatelyInvokedArrowFunction(statements);
ts.setEmitFlags(iife, 33554432 /* TypeScriptClassWrapper */);
var varStatement = ts.createVariableStatement(
/*modifiers*/ undefined, ts.createVariableDeclarationList([
ts.createVariableDeclaration(ts.getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ false),
/*type*/ undefined, ts.createImmediatelyInvokedFunctionExpression(statements))
/*type*/ undefined, iife)
]));
ts.setOriginalNode(varStatement, node);
ts.setCommentRange(varStatement, node);
@@ -52541,7 +52608,7 @@ var ts;
var name = ts.getMutableClone(node);
name.flags &= ~8 /* Synthesized */;
name.original = undefined;
name.parent = currentScope;
name.parent = ts.getParseTreeNode(currentScope); // ensure the parent is set to a parse tree node.
if (useFallback) {
return ts.createLogicalAnd(ts.createStrictInequality(ts.createTypeOf(name), ts.createLiteral("undefined")), name);
}
@@ -54222,7 +54289,7 @@ var ts;
chunkObject.push(ts.createPropertyAssignment(p.name, ts.visitNode(p.initializer, visitor, ts.isExpression)));
}
else {
chunkObject.push(e);
chunkObject.push(ts.visitNode(e, visitor, ts.isObjectLiteralElementLike));
}
}
}
@@ -55457,58 +55524,12 @@ var ts;
&& node.kind === 219 /* ReturnStatement */
&& !node.expression;
}
function isClassLikeVariableStatement(node) {
if (!ts.isVariableStatement(node))
return false;
var variable = ts.singleOrUndefined(node.declarationList.declarations);
return variable
&& variable.initializer
&& ts.isIdentifier(variable.name)
&& (ts.isClassLike(variable.initializer)
|| (ts.isAssignmentExpression(variable.initializer)
&& ts.isIdentifier(variable.initializer.left)
&& ts.isClassLike(variable.initializer.right)));
}
function isTypeScriptClassWrapper(node) {
var call = ts.tryCast(node, ts.isCallExpression);
if (!call || ts.isParseTreeNode(call) ||
ts.some(call.typeArguments) ||
ts.some(call.arguments)) {
return false;
}
var func = ts.tryCast(ts.skipOuterExpressions(call.expression), ts.isFunctionExpression);
if (!func || ts.isParseTreeNode(func) ||
ts.some(func.typeParameters) ||
ts.some(func.parameters) ||
func.type ||
!func.body) {
return false;
}
var statements = func.body.statements;
if (statements.length < 2) {
return false;
}
var firstStatement = statements[0];
if (ts.isParseTreeNode(firstStatement) ||
!ts.isClassLike(firstStatement) &&
!isClassLikeVariableStatement(firstStatement)) {
return false;
}
var lastStatement = ts.elementAt(statements, -1);
var returnStatement = ts.tryCast(ts.isVariableStatement(lastStatement) ? ts.elementAt(statements, -2) : lastStatement, ts.isReturnStatement);
if (!returnStatement ||
!returnStatement.expression ||
!ts.isIdentifier(ts.skipOuterExpressions(returnStatement.expression))) {
return false;
}
return true;
}
function shouldVisitNode(node) {
return (node.transformFlags & 128 /* ContainsES2015 */) !== 0
|| convertedLoopState !== undefined
|| (hierarchyFacts & 4096 /* ConstructorWithCapturedSuper */ && (ts.isStatement(node) || (node.kind === 207 /* Block */)))
|| (ts.isIterationStatement(node, /*lookInLabeledStatements*/ false) && shouldConvertIterationStatementBody(node))
|| isTypeScriptClassWrapper(node);
|| (ts.getEmitFlags(node) & 33554432 /* TypeScriptClassWrapper */) !== 0;
}
function visitor(node) {
if (shouldVisitNode(node)) {
@@ -57643,7 +57664,7 @@ var ts;
* @param node a CallExpression.
*/
function visitCallExpression(node) {
if (isTypeScriptClassWrapper(node)) {
if (ts.getEmitFlags(node) & 33554432 /* TypeScriptClassWrapper */) {
return visitTypeScriptClassWrapper(node);
}
if (node.transformFlags & 64 /* ES2015 */) {
@@ -57685,7 +57706,7 @@ var ts;
// }())
// We skip any outer expressions in a number of places to get to the innermost
// expression, but we will restore them later to preserve comments and source maps.
var body = ts.cast(ts.skipOuterExpressions(node.expression), ts.isFunctionExpression).body;
var body = ts.cast(ts.cast(ts.skipOuterExpressions(node.expression), ts.isArrowFunction).body, ts.isBlock);
// The class statements are the statements generated by visiting the first statement of the
// body (1), while all other statements are added to remainingStatements (2)
var classStatements = ts.visitNodes(body.statements, visitor, ts.isStatement, 0, 1);
@@ -59725,8 +59746,13 @@ var ts;
}
function transformAndEmitContinueStatement(node) {
var label = findContinueTarget(node.label ? ts.unescapeLeadingUnderscores(node.label.escapedText) : undefined);
ts.Debug.assert(label > 0, "Expected continue statment to point to a valid Label.");
emitBreak(label, /*location*/ node);
if (label > 0) {
emitBreak(label, /*location*/ node);
}
else {
// invalid continue without a containing loop. Leave the node as is, per #17875.
emitStatement(node);
}
}
function visitContinueStatement(node) {
if (inStatementContainingYield) {
@@ -59739,8 +59765,13 @@ var ts;
}
function transformAndEmitBreakStatement(node) {
var label = findBreakTarget(node.label ? ts.unescapeLeadingUnderscores(node.label.escapedText) : undefined);
ts.Debug.assert(label > 0, "Expected break statment to point to a valid Label.");
emitBreak(label, /*location*/ node);
if (label > 0) {
emitBreak(label, /*location*/ node);
}
else {
// invalid break without a containing loop, switch, or labeled statement. Leave the node as is, per #17875.
emitStatement(node);
}
}
function visitBreakStatement(node) {
if (inStatementContainingYield) {
@@ -60344,23 +60375,24 @@ var ts;
* @param labelText An optional name of a containing labeled statement.
*/
function findBreakTarget(labelText) {
ts.Debug.assert(blocks !== undefined);
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsLabeledBreakOrContinue(block) && block.labelText === labelText) {
return block.breakLabel;
}
else if (supportsUnlabeledBreak(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.breakLabel;
if (blockStack) {
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsLabeledBreakOrContinue(block) && block.labelText === labelText) {
return block.breakLabel;
}
else if (supportsUnlabeledBreak(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.breakLabel;
}
}
}
}
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledBreak(block)) {
return block.breakLabel;
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledBreak(block)) {
return block.breakLabel;
}
}
}
}
@@ -60372,20 +60404,21 @@ var ts;
* @param labelText An optional name of a containing labeled statement.
*/
function findContinueTarget(labelText) {
ts.Debug.assert(blocks !== undefined);
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.continueLabel;
if (blockStack) {
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.continueLabel;
}
}
}
}
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block)) {
return block.continueLabel;
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block)) {
return block.continueLabel;
}
}
}
}
@@ -61344,17 +61377,23 @@ var ts;
*/
function addExportEqualsIfNeeded(statements, emitAsReturn) {
if (currentModuleInfo.exportEquals) {
if (emitAsReturn) {
var statement = ts.createReturn(currentModuleInfo.exportEquals.expression);
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 384 /* NoTokenSourceMaps */ | 1536 /* NoComments */);
statements.push(statement);
}
else {
var statement = ts.createStatement(ts.createAssignment(ts.createPropertyAccess(ts.createIdentifier("module"), "exports"), currentModuleInfo.exportEquals.expression));
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 1536 /* NoComments */);
statements.push(statement);
var expressionResult = importCallExpressionVisitor(currentModuleInfo.exportEquals.expression);
if (expressionResult) {
if (expressionResult instanceof Array) {
return ts.Debug.fail("export= expression should never be replaced with multiple expressions!");
}
if (emitAsReturn) {
var statement = ts.createReturn(expressionResult);
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 384 /* NoTokenSourceMaps */ | 1536 /* NoComments */);
statements.push(statement);
}
else {
var statement = ts.createStatement(ts.createAssignment(ts.createPropertyAccess(ts.createIdentifier("module"), "exports"), expressionResult));
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 1536 /* NoComments */);
statements.push(statement);
}
}
}
}
@@ -61899,7 +61938,7 @@ var ts;
return statements;
}
if (ts.hasModifier(decl, 1 /* Export */)) {
var exportName = ts.hasModifier(decl, 512 /* Default */) ? ts.createIdentifier("default") : decl.name;
var exportName = ts.hasModifier(decl, 512 /* Default */) ? ts.createIdentifier("default") : ts.getDeclarationName(decl);
statements = appendExportStatement(statements, exportName, ts.getLocalName(decl), /*location*/ decl);
}
if (decl.name) {
@@ -89591,16 +89630,7 @@ var ts;
if (errors) {
return { errors: errors };
}
// If our selection is the expression in an ExpressionStatement, expand
// the selection to include the enclosing Statement (this stops us
// from trying to care about the return value of the extracted function
// and eliminates double semicolon insertion in certain scenarios)
var range = ts.isStatement(start)
? [start]
: start.parent && start.parent.kind === 210 /* ExpressionStatement */
? [start.parent]
: start;
return { targetRange: { range: range, facts: rangeFacts, declarations: declarations } };
return { targetRange: { range: getStatementOrExpressionRange(start), facts: rangeFacts, declarations: declarations } };
}
function createErrorResult(sourceFile, start, length, message) {
return { errors: [ts.createFileDiagnostic(sourceFile, start, length, message)] };
@@ -89802,6 +89832,19 @@ var ts;
}
}
extractMethod_1.getRangeToExtract = getRangeToExtract;
function getStatementOrExpressionRange(node) {
if (ts.isStatement(node)) {
return [node];
}
else if (ts.isPartOfExpression(node)) {
// If our selection is the expression in an ExpressionStatement, expand
// the selection to include the enclosing Statement (this stops us
// from trying to care about the return value of the extracted function
// and eliminates double semicolon insertion in certain scenarios)
return ts.isExpressionStatement(node.parent) ? [node.parent] : node;
}
return undefined;
}
function isValidExtractionTarget(node) {
// Note that we don't use isFunctionLike because we don't want to put the extracted closure *inside* a method
return (node.kind === 228 /* FunctionDeclaration */) || ts.isSourceFile(node) || isModuleBlock(node) || ts.isClassLike(node);
@@ -89889,32 +89932,32 @@ var ts;
return "constructor";
case 186 /* FunctionExpression */:
return scope.name
? "function expression " + scope.name.getText()
? "function expression " + scope.name.text
: "anonymous function expression";
case 228 /* FunctionDeclaration */:
return "function " + scope.name.getText();
return "function '" + scope.name.text + "'";
case 187 /* ArrowFunction */:
return "arrow function";
case 151 /* MethodDeclaration */:
return "method " + scope.name.getText();
return "method '" + scope.name.getText();
case 153 /* GetAccessor */:
return "get " + scope.name.getText();
return "'get " + scope.name.getText() + "'";
case 154 /* SetAccessor */:
return "set " + scope.name.getText();
return "'set " + scope.name.getText() + "'";
}
}
else if (isModuleBlock(scope)) {
return "namespace " + scope.parent.name.getText();
return "namespace '" + scope.parent.name.getText() + "'";
}
else if (ts.isClassLike(scope)) {
return scope.kind === 229 /* ClassDeclaration */
? "class " + scope.name.text
? "class '" + scope.name.text + "'"
: scope.name.text
? "class expression " + scope.name.text
? "class expression '" + scope.name.text + "'"
: "anonymous class expression";
}
else if (ts.isSourceFile(scope)) {
return "file '" + scope.fileName + "'";
return scope.externalModuleIndicator ? "module scope" : "global scope";
}
else {
return "unknown";
+2
View File
@@ -3388,6 +3388,8 @@ declare namespace ts {
function updateBundle(node: Bundle, sourceFiles: SourceFile[]): Bundle;
function createImmediatelyInvokedFunctionExpression(statements: Statement[]): CallExpression;
function createImmediatelyInvokedFunctionExpression(statements: Statement[], param: ParameterDeclaration, paramValue: Expression): CallExpression;
function createImmediatelyInvokedArrowFunction(statements: Statement[]): CallExpression;
function createImmediatelyInvokedArrowFunction(statements: Statement[], param: ParameterDeclaration, paramValue: Expression): CallExpression;
function createComma(left: Expression, right: Expression): Expression;
function createLessThan(left: Expression, right: Expression): Expression;
function createAssignment(left: ObjectLiteralExpression | ArrayLiteralExpression, right: Expression): DestructuringAssignment;
+172 -129
View File
@@ -1201,6 +1201,7 @@ var ts;
EmitFlags[EmitFlags["HasEndOfDeclarationMarker"] = 4194304] = "HasEndOfDeclarationMarker";
EmitFlags[EmitFlags["Iterator"] = 8388608] = "Iterator";
EmitFlags[EmitFlags["NoAsciiEscaping"] = 16777216] = "NoAsciiEscaping";
/*@internal*/ EmitFlags[EmitFlags["TypeScriptClassWrapper"] = 33554432] = "TypeScriptClassWrapper";
})(EmitFlags = ts.EmitFlags || (ts.EmitFlags = {}));
/**
* Used by the checker, this enum keeps track of external emit helpers that should be type
@@ -5080,7 +5081,7 @@ var ts;
Convert_function_to_an_ES2015_class: diag(95001, ts.DiagnosticCategory.Message, "Convert_function_to_an_ES2015_class_95001", "Convert function to an ES2015 class"),
Convert_function_0_to_class: diag(95002, ts.DiagnosticCategory.Message, "Convert_function_0_to_class_95002", "Convert function '{0}' to class"),
Extract_function: diag(95003, ts.DiagnosticCategory.Message, "Extract_function_95003", "Extract function"),
Extract_function_into_0: diag(95004, ts.DiagnosticCategory.Message, "Extract_function_into_0_95004", "Extract function into '{0}'"),
Extract_function_into_0: diag(95004, ts.DiagnosticCategory.Message, "Extract_function_into_0_95004", "Extract function into {0}"),
};
})(ts || (ts = {}));
/// <reference path="core.ts"/>
@@ -8844,9 +8845,9 @@ var ts;
|| kind === 265 /* SourceFile */;
}
ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment;
function nodeIsSynthesized(node) {
return ts.positionIsSynthesized(node.pos)
|| ts.positionIsSynthesized(node.end);
function nodeIsSynthesized(range) {
return ts.positionIsSynthesized(range.pos)
|| ts.positionIsSynthesized(range.end);
}
ts.nodeIsSynthesized = nodeIsSynthesized;
function getOriginalSourceFile(sourceFile) {
@@ -23319,12 +23320,17 @@ var ts;
// 2. inside a function
// 3. inside an instance property initializer, a reference to a non-instance property
// 4. inside a static property initializer, a reference to a static method in the same class
// 5. inside a TS export= declaration (since we will move the export statement during emit to avoid TDZ)
// or if usage is in a type context:
// 1. inside a type query (typeof in type position)
if (usage.parent.kind === 246 /* ExportSpecifier */) {
if (usage.parent.kind === 246 /* ExportSpecifier */ || (usage.parent.kind === 243 /* ExportAssignment */ && usage.parent.isExportEquals)) {
// export specifiers do not use the variable, they only make it available for use
return true;
}
// When resolving symbols for exports, the `usage` location passed in can be the export site directly
if (usage.kind === 243 /* ExportAssignment */ && usage.isExportEquals) {
return true;
}
var container = ts.getEnclosingBlockScopeContainer(declaration);
return isInTypeQuery(usage) || isUsedInFunctionOrInstanceProperty(usage, declaration, container);
function isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration, usage) {
@@ -28615,6 +28621,9 @@ var ts;
}
return signature.resolvedReturnType;
}
function isResolvingReturnTypeOfSignature(signature) {
return !signature.resolvedReturnType && findResolutionCycleStartIndex(signature, 3 /* ResolvedReturnType */) >= 0;
}
function getRestTypeOfSignature(signature) {
if (signature.hasRestParameter) {
var type = getTypeOfSymbol(ts.lastOrUndefined(signature.parameters));
@@ -34496,7 +34505,7 @@ var ts;
// Otherwise, if the containing function is contextually typed by a function type with exactly one call signature
// and that call signature is non-generic, return statements are contextually typed by the return type of the signature
var signature = getContextualSignatureForFunctionLikeDeclaration(functionDecl);
if (signature) {
if (signature && !isResolvingReturnTypeOfSignature(signature)) {
return getReturnTypeOfSignature(signature);
}
return undefined;
@@ -37549,7 +37558,7 @@ var ts;
* file.
*/
function isJavaScriptConstructor(node) {
if (ts.isInJavaScriptFile(node)) {
if (node && ts.isInJavaScriptFile(node)) {
// If the node has a @class tag, treat it like a constructor.
if (ts.getJSDocClassTag(node))
return true;
@@ -37561,6 +37570,20 @@ var ts;
}
return false;
}
function getJavaScriptClassType(symbol) {
if (ts.isDeclarationOfFunctionOrClassExpression(symbol)) {
symbol = getSymbolOfNode(symbol.valueDeclaration.initializer);
}
if (isJavaScriptConstructor(symbol.valueDeclaration)) {
return getInferredClassType(symbol);
}
if (symbol.flags & 3 /* Variable */) {
var valueType = getTypeOfSymbol(symbol);
if (valueType.symbol && !isInferredClassType(valueType) && isJavaScriptConstructor(valueType.symbol.valueDeclaration)) {
return getInferredClassType(valueType.symbol);
}
}
}
function getInferredClassType(symbol) {
var links = getSymbolLinks(symbol);
if (!links.inferredClassType) {
@@ -37600,13 +37623,11 @@ var ts;
var funcSymbol = node.expression.kind === 71 /* Identifier */ ?
getResolvedSymbol(node.expression) :
checkExpression(node.expression).symbol;
if (funcSymbol && ts.isDeclarationOfFunctionOrClassExpression(funcSymbol)) {
funcSymbol = getSymbolOfNode(funcSymbol.valueDeclaration.initializer);
var type = funcSymbol && getJavaScriptClassType(funcSymbol);
if (type) {
return type;
}
if (funcSymbol && funcSymbol.flags & 16 /* Function */ && (funcSymbol.members || ts.getJSDocClassTag(funcSymbol.valueDeclaration))) {
return getInferredClassType(funcSymbol);
}
else if (noImplicitAny) {
if (noImplicitAny) {
error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
}
return anyType;
@@ -40064,6 +40085,8 @@ var ts;
: 4 /* ExportNamespace */;
case 229 /* ClassDeclaration */:
case 232 /* EnumDeclaration */:
// A NamespaceImport declares an Alias, which is allowed to merge with other values within the module
case 240 /* NamespaceImport */:
return 2 /* ExportType */ | 1 /* ExportValue */;
case 237 /* ImportEqualsDeclaration */:
var result_3 = 0 /* None */;
@@ -43921,6 +43944,15 @@ var ts;
return type.flags & 32768 /* Object */ && getSignaturesOfType(type, 0 /* Call */).length > 0;
}
function getTypeReferenceSerializationKind(typeName, location) {
// ensure both `typeName` and `location` are parse tree nodes.
typeName = ts.getParseTreeNode(typeName, ts.isEntityName);
if (!typeName)
return ts.TypeReferenceSerializationKind.Unknown;
if (location) {
location = ts.getParseTreeNode(location);
if (!location)
return ts.TypeReferenceSerializationKind.Unknown;
}
// Resolve the symbol as a value to ensure the type can be reached at runtime during emit.
var valueSymbol = resolveEntityName(typeName, 107455 /* Value */, /*ignoreErrors*/ true, /*dontResolveAlias*/ false, location);
// Resolve the symbol as a type so that we can provide a more useful hint for the type serializer.
@@ -47563,6 +47595,17 @@ var ts;
/*argumentsArray*/ paramValue ? [paramValue] : []);
}
ts.createImmediatelyInvokedFunctionExpression = createImmediatelyInvokedFunctionExpression;
function createImmediatelyInvokedArrowFunction(statements, param, paramValue) {
return createCall(createArrowFunction(
/*modifiers*/ undefined,
/*typeParameters*/ undefined,
/*parameters*/ param ? [param] : [],
/*type*/ undefined,
/*equalsGreaterThanToken*/ undefined, createBlock(statements, /*multiLine*/ true)),
/*typeArguments*/ undefined,
/*argumentsArray*/ paramValue ? [paramValue] : []);
}
ts.createImmediatelyInvokedArrowFunction = createImmediatelyInvokedArrowFunction;
function createComma(left, right) {
return createBinary(left, 26 /* CommaToken */, right);
}
@@ -48963,9 +49006,31 @@ var ts;
case 288 /* PartiallyEmittedExpression */: return ts.updatePartiallyEmittedExpression(outerExpression, expression);
}
}
/**
* Determines whether a node is a parenthesized expression that can be ignored when recreating outer expressions.
*
* A parenthesized expression can be ignored when all of the following are true:
*
* - It's `pos` and `end` are not -1
* - It does not have a custom source map range
* - It does not have a custom comment range
* - It does not have synthetic leading or trailing comments
*
* If an outermost parenthesized expression is ignored, but the containing expression requires a parentheses around
* the expression to maintain precedence, a new parenthesized expression should be created automatically when
* the containing expression is created/updated.
*/
function isIgnorableParen(node) {
return node.kind === 185 /* ParenthesizedExpression */
&& ts.nodeIsSynthesized(node)
&& ts.nodeIsSynthesized(ts.getSourceMapRange(node))
&& ts.nodeIsSynthesized(ts.getCommentRange(node))
&& !ts.some(ts.getSyntheticLeadingComments(node))
&& !ts.some(ts.getSyntheticTrailingComments(node));
}
function recreateOuterExpressions(outerExpression, innerExpression, kinds) {
if (kinds === void 0) { kinds = 7 /* All */; }
if (outerExpression && isOuterExpression(outerExpression, kinds)) {
if (outerExpression && isOuterExpression(outerExpression, kinds) && !isIgnorableParen(outerExpression)) {
return updateOuterExpression(outerExpression, recreateOuterExpressions(outerExpression.expression, innerExpression));
}
return innerExpression;
@@ -50417,7 +50482,7 @@ var ts;
else {
// export class x { }
var name = node.name;
if (!uniqueExports.get(ts.unescapeLeadingUnderscores(name.escapedText))) {
if (name && !uniqueExports.get(ts.unescapeLeadingUnderscores(name.escapedText))) {
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name);
uniqueExports.set(ts.unescapeLeadingUnderscores(name.escapedText), true);
exportedNames = ts.append(exportedNames, name);
@@ -51435,10 +51500,12 @@ var ts;
ts.setEmitFlags(statement, 1536 /* NoComments */ | 384 /* NoTokenSourceMaps */);
statements.push(statement);
ts.addRange(statements, context.endLexicalEnvironment());
var iife = ts.createImmediatelyInvokedArrowFunction(statements);
ts.setEmitFlags(iife, 33554432 /* TypeScriptClassWrapper */);
var varStatement = ts.createVariableStatement(
/*modifiers*/ undefined, ts.createVariableDeclarationList([
ts.createVariableDeclaration(ts.getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ false),
/*type*/ undefined, ts.createImmediatelyInvokedFunctionExpression(statements))
/*type*/ undefined, iife)
]));
ts.setOriginalNode(varStatement, node);
ts.setCommentRange(varStatement, node);
@@ -52541,7 +52608,7 @@ var ts;
var name = ts.getMutableClone(node);
name.flags &= ~8 /* Synthesized */;
name.original = undefined;
name.parent = currentScope;
name.parent = ts.getParseTreeNode(currentScope); // ensure the parent is set to a parse tree node.
if (useFallback) {
return ts.createLogicalAnd(ts.createStrictInequality(ts.createTypeOf(name), ts.createLiteral("undefined")), name);
}
@@ -54222,7 +54289,7 @@ var ts;
chunkObject.push(ts.createPropertyAssignment(p.name, ts.visitNode(p.initializer, visitor, ts.isExpression)));
}
else {
chunkObject.push(e);
chunkObject.push(ts.visitNode(e, visitor, ts.isObjectLiteralElementLike));
}
}
}
@@ -55457,58 +55524,12 @@ var ts;
&& node.kind === 219 /* ReturnStatement */
&& !node.expression;
}
function isClassLikeVariableStatement(node) {
if (!ts.isVariableStatement(node))
return false;
var variable = ts.singleOrUndefined(node.declarationList.declarations);
return variable
&& variable.initializer
&& ts.isIdentifier(variable.name)
&& (ts.isClassLike(variable.initializer)
|| (ts.isAssignmentExpression(variable.initializer)
&& ts.isIdentifier(variable.initializer.left)
&& ts.isClassLike(variable.initializer.right)));
}
function isTypeScriptClassWrapper(node) {
var call = ts.tryCast(node, ts.isCallExpression);
if (!call || ts.isParseTreeNode(call) ||
ts.some(call.typeArguments) ||
ts.some(call.arguments)) {
return false;
}
var func = ts.tryCast(ts.skipOuterExpressions(call.expression), ts.isFunctionExpression);
if (!func || ts.isParseTreeNode(func) ||
ts.some(func.typeParameters) ||
ts.some(func.parameters) ||
func.type ||
!func.body) {
return false;
}
var statements = func.body.statements;
if (statements.length < 2) {
return false;
}
var firstStatement = statements[0];
if (ts.isParseTreeNode(firstStatement) ||
!ts.isClassLike(firstStatement) &&
!isClassLikeVariableStatement(firstStatement)) {
return false;
}
var lastStatement = ts.elementAt(statements, -1);
var returnStatement = ts.tryCast(ts.isVariableStatement(lastStatement) ? ts.elementAt(statements, -2) : lastStatement, ts.isReturnStatement);
if (!returnStatement ||
!returnStatement.expression ||
!ts.isIdentifier(ts.skipOuterExpressions(returnStatement.expression))) {
return false;
}
return true;
}
function shouldVisitNode(node) {
return (node.transformFlags & 128 /* ContainsES2015 */) !== 0
|| convertedLoopState !== undefined
|| (hierarchyFacts & 4096 /* ConstructorWithCapturedSuper */ && (ts.isStatement(node) || (node.kind === 207 /* Block */)))
|| (ts.isIterationStatement(node, /*lookInLabeledStatements*/ false) && shouldConvertIterationStatementBody(node))
|| isTypeScriptClassWrapper(node);
|| (ts.getEmitFlags(node) & 33554432 /* TypeScriptClassWrapper */) !== 0;
}
function visitor(node) {
if (shouldVisitNode(node)) {
@@ -57643,7 +57664,7 @@ var ts;
* @param node a CallExpression.
*/
function visitCallExpression(node) {
if (isTypeScriptClassWrapper(node)) {
if (ts.getEmitFlags(node) & 33554432 /* TypeScriptClassWrapper */) {
return visitTypeScriptClassWrapper(node);
}
if (node.transformFlags & 64 /* ES2015 */) {
@@ -57685,7 +57706,7 @@ var ts;
// }())
// We skip any outer expressions in a number of places to get to the innermost
// expression, but we will restore them later to preserve comments and source maps.
var body = ts.cast(ts.skipOuterExpressions(node.expression), ts.isFunctionExpression).body;
var body = ts.cast(ts.cast(ts.skipOuterExpressions(node.expression), ts.isArrowFunction).body, ts.isBlock);
// The class statements are the statements generated by visiting the first statement of the
// body (1), while all other statements are added to remainingStatements (2)
var classStatements = ts.visitNodes(body.statements, visitor, ts.isStatement, 0, 1);
@@ -59725,8 +59746,13 @@ var ts;
}
function transformAndEmitContinueStatement(node) {
var label = findContinueTarget(node.label ? ts.unescapeLeadingUnderscores(node.label.escapedText) : undefined);
ts.Debug.assert(label > 0, "Expected continue statment to point to a valid Label.");
emitBreak(label, /*location*/ node);
if (label > 0) {
emitBreak(label, /*location*/ node);
}
else {
// invalid continue without a containing loop. Leave the node as is, per #17875.
emitStatement(node);
}
}
function visitContinueStatement(node) {
if (inStatementContainingYield) {
@@ -59739,8 +59765,13 @@ var ts;
}
function transformAndEmitBreakStatement(node) {
var label = findBreakTarget(node.label ? ts.unescapeLeadingUnderscores(node.label.escapedText) : undefined);
ts.Debug.assert(label > 0, "Expected break statment to point to a valid Label.");
emitBreak(label, /*location*/ node);
if (label > 0) {
emitBreak(label, /*location*/ node);
}
else {
// invalid break without a containing loop, switch, or labeled statement. Leave the node as is, per #17875.
emitStatement(node);
}
}
function visitBreakStatement(node) {
if (inStatementContainingYield) {
@@ -60344,23 +60375,24 @@ var ts;
* @param labelText An optional name of a containing labeled statement.
*/
function findBreakTarget(labelText) {
ts.Debug.assert(blocks !== undefined);
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsLabeledBreakOrContinue(block) && block.labelText === labelText) {
return block.breakLabel;
}
else if (supportsUnlabeledBreak(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.breakLabel;
if (blockStack) {
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsLabeledBreakOrContinue(block) && block.labelText === labelText) {
return block.breakLabel;
}
else if (supportsUnlabeledBreak(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.breakLabel;
}
}
}
}
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledBreak(block)) {
return block.breakLabel;
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledBreak(block)) {
return block.breakLabel;
}
}
}
}
@@ -60372,20 +60404,21 @@ var ts;
* @param labelText An optional name of a containing labeled statement.
*/
function findContinueTarget(labelText) {
ts.Debug.assert(blocks !== undefined);
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.continueLabel;
if (blockStack) {
if (labelText) {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block) && hasImmediateContainingLabeledBlock(labelText, i - 1)) {
return block.continueLabel;
}
}
}
}
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block)) {
return block.continueLabel;
else {
for (var i = blockStack.length - 1; i >= 0; i--) {
var block = blockStack[i];
if (supportsUnlabeledContinue(block)) {
return block.continueLabel;
}
}
}
}
@@ -61344,17 +61377,23 @@ var ts;
*/
function addExportEqualsIfNeeded(statements, emitAsReturn) {
if (currentModuleInfo.exportEquals) {
if (emitAsReturn) {
var statement = ts.createReturn(currentModuleInfo.exportEquals.expression);
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 384 /* NoTokenSourceMaps */ | 1536 /* NoComments */);
statements.push(statement);
}
else {
var statement = ts.createStatement(ts.createAssignment(ts.createPropertyAccess(ts.createIdentifier("module"), "exports"), currentModuleInfo.exportEquals.expression));
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 1536 /* NoComments */);
statements.push(statement);
var expressionResult = importCallExpressionVisitor(currentModuleInfo.exportEquals.expression);
if (expressionResult) {
if (expressionResult instanceof Array) {
return ts.Debug.fail("export= expression should never be replaced with multiple expressions!");
}
if (emitAsReturn) {
var statement = ts.createReturn(expressionResult);
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 384 /* NoTokenSourceMaps */ | 1536 /* NoComments */);
statements.push(statement);
}
else {
var statement = ts.createStatement(ts.createAssignment(ts.createPropertyAccess(ts.createIdentifier("module"), "exports"), expressionResult));
ts.setTextRange(statement, currentModuleInfo.exportEquals);
ts.setEmitFlags(statement, 1536 /* NoComments */);
statements.push(statement);
}
}
}
}
@@ -61899,7 +61938,7 @@ var ts;
return statements;
}
if (ts.hasModifier(decl, 1 /* Export */)) {
var exportName = ts.hasModifier(decl, 512 /* Default */) ? ts.createIdentifier("default") : decl.name;
var exportName = ts.hasModifier(decl, 512 /* Default */) ? ts.createIdentifier("default") : ts.getDeclarationName(decl);
statements = appendExportStatement(statements, exportName, ts.getLocalName(decl), /*location*/ decl);
}
if (decl.name) {
@@ -89591,16 +89630,7 @@ var ts;
if (errors) {
return { errors: errors };
}
// If our selection is the expression in an ExpressionStatement, expand
// the selection to include the enclosing Statement (this stops us
// from trying to care about the return value of the extracted function
// and eliminates double semicolon insertion in certain scenarios)
var range = ts.isStatement(start)
? [start]
: start.parent && start.parent.kind === 210 /* ExpressionStatement */
? [start.parent]
: start;
return { targetRange: { range: range, facts: rangeFacts, declarations: declarations } };
return { targetRange: { range: getStatementOrExpressionRange(start), facts: rangeFacts, declarations: declarations } };
}
function createErrorResult(sourceFile, start, length, message) {
return { errors: [ts.createFileDiagnostic(sourceFile, start, length, message)] };
@@ -89802,6 +89832,19 @@ var ts;
}
}
extractMethod_1.getRangeToExtract = getRangeToExtract;
function getStatementOrExpressionRange(node) {
if (ts.isStatement(node)) {
return [node];
}
else if (ts.isPartOfExpression(node)) {
// If our selection is the expression in an ExpressionStatement, expand
// the selection to include the enclosing Statement (this stops us
// from trying to care about the return value of the extracted function
// and eliminates double semicolon insertion in certain scenarios)
return ts.isExpressionStatement(node.parent) ? [node.parent] : node;
}
return undefined;
}
function isValidExtractionTarget(node) {
// Note that we don't use isFunctionLike because we don't want to put the extracted closure *inside* a method
return (node.kind === 228 /* FunctionDeclaration */) || ts.isSourceFile(node) || isModuleBlock(node) || ts.isClassLike(node);
@@ -89889,32 +89932,32 @@ var ts;
return "constructor";
case 186 /* FunctionExpression */:
return scope.name
? "function expression " + scope.name.getText()
? "function expression " + scope.name.text
: "anonymous function expression";
case 228 /* FunctionDeclaration */:
return "function " + scope.name.getText();
return "function '" + scope.name.text + "'";
case 187 /* ArrowFunction */:
return "arrow function";
case 151 /* MethodDeclaration */:
return "method " + scope.name.getText();
return "method '" + scope.name.getText();
case 153 /* GetAccessor */:
return "get " + scope.name.getText();
return "'get " + scope.name.getText() + "'";
case 154 /* SetAccessor */:
return "set " + scope.name.getText();
return "'set " + scope.name.getText() + "'";
}
}
else if (isModuleBlock(scope)) {
return "namespace " + scope.parent.name.getText();
return "namespace '" + scope.parent.name.getText() + "'";
}
else if (ts.isClassLike(scope)) {
return scope.kind === 229 /* ClassDeclaration */
? "class " + scope.name.text
? "class '" + scope.name.text + "'"
: scope.name.text
? "class expression " + scope.name.text
? "class expression '" + scope.name.text + "'"
: "anonymous class expression";
}
else if (ts.isSourceFile(scope)) {
return "file '" + scope.fileName + "'";
return scope.externalModuleIndicator ? "module scope" : "global scope";
}
else {
return "unknown";
+8 -7
View File
@@ -3531,7 +3531,7 @@ var ts;
Convert_function_to_an_ES2015_class: diag(95001, ts.DiagnosticCategory.Message, "Convert_function_to_an_ES2015_class_95001", "Convert function to an ES2015 class"),
Convert_function_0_to_class: diag(95002, ts.DiagnosticCategory.Message, "Convert_function_0_to_class_95002", "Convert function '{0}' to class"),
Extract_function: diag(95003, ts.DiagnosticCategory.Message, "Extract_function_95003", "Extract function"),
Extract_function_into_0: diag(95004, ts.DiagnosticCategory.Message, "Extract_function_into_0_95004", "Extract function into '{0}'"),
Extract_function_into_0: diag(95004, ts.DiagnosticCategory.Message, "Extract_function_into_0_95004", "Extract function into {0}"),
};
})(ts || (ts = {}));
var ts;
@@ -5290,9 +5290,9 @@ var ts;
|| kind === 265;
}
ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment;
function nodeIsSynthesized(node) {
return ts.positionIsSynthesized(node.pos)
|| ts.positionIsSynthesized(node.end);
function nodeIsSynthesized(range) {
return ts.positionIsSynthesized(range.pos)
|| ts.positionIsSynthesized(range.end);
}
ts.nodeIsSynthesized = nodeIsSynthesized;
function getOriginalSourceFile(sourceFile) {
@@ -17565,6 +17565,7 @@ var ts;
}
};
TypingsInstaller.prototype.install = function (req) {
var _this = this;
if (this.log.isEnabled()) {
this.log.writeLine("Got install request " + JSON.stringify(req));
}
@@ -17577,7 +17578,7 @@ var ts;
if (this.safeList === undefined) {
this.safeList = ts.JsTyping.loadSafeList(this.installTypingHost, this.safeListPath);
}
var discoverTypingsResult = ts.JsTyping.discoverTypings(this.installTypingHost, this.log.isEnabled() ? this.log.writeLine : undefined, req.fileNames, req.projectRootPath, this.safeList, this.packageNameToTypingLocation, req.typeAcquisition, req.unresolvedImports);
var discoverTypingsResult = ts.JsTyping.discoverTypings(this.installTypingHost, this.log.isEnabled() ? (function (s) { return _this.log.writeLine(s); }) : undefined, req.fileNames, req.projectRootPath, this.safeList, this.packageNameToTypingLocation, req.typeAcquisition, req.unresolvedImports);
if (this.log.isEnabled()) {
this.log.writeLine("Finished typings discovery: " + JSON.stringify(discoverTypingsResult));
}
@@ -17919,7 +17920,7 @@ var ts;
if (_this.log.isEnabled()) {
_this.log.writeLine("Updating " + TypesRegistryPackageName + " npm package...");
}
_this.execSync(_this.npmPath + " install " + TypesRegistryPackageName, { cwd: globalTypingsCacheLocation, stdio: "ignore" });
_this.execSync(_this.npmPath + " install --ignore-scripts " + TypesRegistryPackageName, { cwd: globalTypingsCacheLocation, stdio: "ignore" });
if (_this.log.isEnabled()) {
_this.log.writeLine("Updated " + TypesRegistryPackageName + " npm package");
}
@@ -17965,7 +17966,7 @@ var ts;
if (this.log.isEnabled()) {
this.log.writeLine("#" + requestId + " with arguments'" + JSON.stringify(args) + "'.");
}
var command = this.npmPath + " install " + args.join(" ") + " --save-dev --user-agent=\"typesInstaller/" + ts.version + "\"";
var command = this.npmPath + " install --ignore-scripts " + args.join(" ") + " --save-dev --user-agent=\"typesInstaller/" + ts.version + "\"";
var start = Date.now();
var stdout;
var stderr;