mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 11:35:42 -06:00
Minor cleanup
This commit is contained in:
parent
e97368bb3f
commit
f025e0caed
@ -109,12 +109,12 @@ namespace ts {
|
||||
export function createLiteral(value: string | number | boolean, location?: TextRange): PrimaryExpression;
|
||||
export function createLiteral(value: string | number | boolean | StringLiteral | Identifier, location?: TextRange): PrimaryExpression {
|
||||
if (typeof value === "number") {
|
||||
const node = <LiteralExpression>createNode(SyntaxKind.NumericLiteral, location, /*flags*/ undefined);
|
||||
const node = <NumericLiteral>createNode(SyntaxKind.NumericLiteral, location, /*flags*/ undefined);
|
||||
node.text = value.toString();
|
||||
return node;
|
||||
}
|
||||
else if (typeof value === "boolean") {
|
||||
return <PrimaryExpression>createNode(value ? SyntaxKind.TrueKeyword : SyntaxKind.FalseKeyword, location, /*flags*/ undefined);
|
||||
return <BooleanLiteral>createNode(value ? SyntaxKind.TrueKeyword : SyntaxKind.FalseKeyword, location, /*flags*/ undefined);
|
||||
}
|
||||
else if (typeof value === "string") {
|
||||
const node = <StringLiteral>createNode(SyntaxKind.StringLiteral, location, /*flags*/ undefined);
|
||||
@ -226,20 +226,7 @@ namespace ts {
|
||||
|
||||
// Signature elements
|
||||
|
||||
export function createParameter(name: string | Identifier | BindingPattern, initializer?: Expression, location?: TextRange) {
|
||||
return createParameterDeclaration(
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
/*dotDotDotToken*/ undefined,
|
||||
name,
|
||||
/*questionToken*/ undefined,
|
||||
/*type*/ undefined,
|
||||
initializer,
|
||||
location
|
||||
);
|
||||
}
|
||||
|
||||
export function createParameterDeclaration(decorators: Decorator[], modifiers: Modifier[], dotDotDotToken: DotDotDotToken, name: string | Identifier | BindingPattern, questionToken: QuestionToken, type: TypeNode, initializer: Expression, location?: TextRange, flags?: NodeFlags) {
|
||||
export function createParameter(decorators: Decorator[], modifiers: Modifier[], dotDotDotToken: DotDotDotToken, name: string | Identifier | BindingPattern, questionToken?: QuestionToken, type?: TypeNode, initializer?: Expression, location?: TextRange, flags?: NodeFlags) {
|
||||
const node = <ParameterDeclaration>createNode(SyntaxKind.Parameter, location, flags);
|
||||
node.decorators = decorators ? createNodeArray(decorators) : undefined;
|
||||
node.modifiers = modifiers ? createNodeArray(modifiers) : undefined;
|
||||
@ -251,9 +238,9 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function updateParameterDeclaration(node: ParameterDeclaration, decorators: Decorator[], modifiers: Modifier[], name: BindingName, type: TypeNode, initializer: Expression) {
|
||||
export function updateParameter(node: ParameterDeclaration, decorators: Decorator[], modifiers: Modifier[], name: BindingName, type: TypeNode, initializer: Expression) {
|
||||
if (node.decorators !== decorators || node.modifiers !== modifiers || node.name !== name || node.type !== type || node.initializer !== initializer) {
|
||||
return updateNode(createParameterDeclaration(decorators, modifiers, node.dotDotDotToken, name, node.questionToken, type, initializer, /*location*/ node, /*flags*/ node.flags), node);
|
||||
return updateNode(createParameter(decorators, modifiers, node.dotDotDotToken, name, node.questionToken, type, initializer, /*location*/ node, /*flags*/ node.flags), node);
|
||||
}
|
||||
|
||||
return node;
|
||||
@ -1557,18 +1544,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function createRestParameter(name: string | Identifier) {
|
||||
return createParameterDeclaration(
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
createToken(SyntaxKind.DotDotDotToken),
|
||||
name,
|
||||
/*questionToken*/ undefined,
|
||||
/*type*/ undefined,
|
||||
/*initializer*/ undefined
|
||||
);
|
||||
}
|
||||
|
||||
export function createFunctionCall(func: Expression, thisArg: Expression, argumentsList: Expression[], location?: TextRange) {
|
||||
return createCall(
|
||||
createPropertyAccess(func, "call"),
|
||||
@ -1781,13 +1756,10 @@ namespace ts {
|
||||
return createArrowFunction(
|
||||
/*modifiers*/ undefined,
|
||||
/*typeParameters*/ undefined,
|
||||
[createParameter("name")],
|
||||
[createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "name")],
|
||||
/*type*/ undefined,
|
||||
/*equalsGreaterThanToken*/ undefined,
|
||||
createElementAccess(
|
||||
target,
|
||||
createIdentifier("name")
|
||||
)
|
||||
createToken(SyntaxKind.EqualsGreaterThanToken),
|
||||
createElementAccess(target, createIdentifier("name"))
|
||||
);
|
||||
}
|
||||
|
||||
@ -1797,11 +1769,11 @@ namespace ts {
|
||||
/*modifiers*/ undefined,
|
||||
/*typeParameters*/ undefined,
|
||||
[
|
||||
createParameter("name"),
|
||||
createParameter("value")
|
||||
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "name"),
|
||||
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "value")
|
||||
],
|
||||
/*type*/ undefined,
|
||||
/*equalsGreaterThanToken*/ undefined,
|
||||
createToken(SyntaxKind.EqualsGreaterThanToken),
|
||||
createAssignment(
|
||||
createElementAccess(
|
||||
target,
|
||||
@ -1853,7 +1825,7 @@ namespace ts {
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
"value",
|
||||
[createParameter("v")],
|
||||
[createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "v")],
|
||||
createBlock([
|
||||
createStatement(
|
||||
createCall(
|
||||
@ -1873,9 +1845,9 @@ namespace ts {
|
||||
createArrowFunction(
|
||||
/*modifiers*/ undefined,
|
||||
/*typeParameters*/ undefined,
|
||||
[createParameter("name")],
|
||||
[createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "name")],
|
||||
/*type*/ undefined,
|
||||
/*equalsGreaterThanToken*/ undefined,
|
||||
createToken(SyntaxKind.EqualsGreaterThanToken),
|
||||
createLogicalOr(
|
||||
createElementAccess(
|
||||
createIdentifier("cache"),
|
||||
@ -1915,8 +1887,8 @@ namespace ts {
|
||||
/*name*/ undefined,
|
||||
/*typeParameters*/ undefined,
|
||||
[
|
||||
createParameter("geti"),
|
||||
createParameter("seti")
|
||||
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "geti"),
|
||||
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "seti")
|
||||
],
|
||||
/*type*/ undefined,
|
||||
createBlock([
|
||||
@ -2246,7 +2218,7 @@ namespace ts {
|
||||
|
||||
/**
|
||||
* Ensures "use strict" directive is added
|
||||
*
|
||||
*
|
||||
* @param node source file
|
||||
*/
|
||||
export function ensureUseStrict(node: SourceFile): SourceFile {
|
||||
|
||||
@ -685,7 +685,7 @@ namespace ts {
|
||||
/*asteriskToken*/ undefined,
|
||||
/*name*/ undefined,
|
||||
/*typeParameters*/ undefined,
|
||||
extendsClauseElement ? [createParameter("_super")] : [],
|
||||
extendsClauseElement ? [createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "_super")] : [],
|
||||
/*type*/ undefined,
|
||||
transformClassBody(node, extendsClauseElement)
|
||||
);
|
||||
@ -1035,7 +1035,12 @@ namespace ts {
|
||||
// evaluated inside the function body.
|
||||
return setOriginalNode(
|
||||
createParameter(
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
/*dotDotDotToken*/ undefined,
|
||||
getGeneratedNameForNode(node),
|
||||
/*questionToken*/ undefined,
|
||||
/*type*/ undefined,
|
||||
/*initializer*/ undefined,
|
||||
/*location*/ node
|
||||
),
|
||||
@ -1046,7 +1051,12 @@ namespace ts {
|
||||
// Initializers are elided
|
||||
return setOriginalNode(
|
||||
createParameter(
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
/*dotDotDotToken*/ undefined,
|
||||
node.name,
|
||||
/*questionToken*/ undefined,
|
||||
/*type*/ undefined,
|
||||
/*initializer*/ undefined,
|
||||
/*location*/ node
|
||||
),
|
||||
@ -2506,7 +2516,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else {
|
||||
loopParameters.push(createParameter(name));
|
||||
loopParameters.push(createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, name));
|
||||
if (resolver.getNodeCheckFlags(decl) & NodeCheckFlags.NeedsLoopOutParameter) {
|
||||
const outParamName = createUniqueName("out_" + name.text);
|
||||
loopOutParameters.push({ originalName: name, outParamName });
|
||||
@ -3081,9 +3091,8 @@ namespace ts {
|
||||
/**
|
||||
* Hooks node substitutions.
|
||||
*
|
||||
* @param emitContext The context for the emitter.
|
||||
* @param node The node to substitute.
|
||||
* @param isExpression A value indicating whether the node is to be used in an expression
|
||||
* position.
|
||||
*/
|
||||
function onSubstituteNode(emitContext: EmitContext, node: Node) {
|
||||
node = previousOnSubstituteNode(emitContext, node);
|
||||
|
||||
@ -2369,7 +2369,7 @@ namespace ts {
|
||||
labelExpressions = [];
|
||||
}
|
||||
|
||||
const expression = <LiteralExpression>createSynthesizedNode(SyntaxKind.NumericLiteral);
|
||||
const expression = createLiteral(-1);
|
||||
if (labelExpressions[label] === undefined) {
|
||||
labelExpressions[label] = [expression];
|
||||
}
|
||||
@ -2380,7 +2380,7 @@ namespace ts {
|
||||
return expression;
|
||||
}
|
||||
|
||||
return <OmittedExpression>createNode(SyntaxKind.OmittedExpression);
|
||||
return createOmittedExpression();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2596,7 +2596,7 @@ namespace ts {
|
||||
/*asteriskToken*/ undefined,
|
||||
/*name*/ undefined,
|
||||
/*typeParameters*/ undefined,
|
||||
[createParameter(state)],
|
||||
[createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, state)],
|
||||
/*type*/ undefined,
|
||||
createBlock(
|
||||
buildResult,
|
||||
|
||||
@ -91,7 +91,7 @@ namespace ts {
|
||||
addRange(statements, endLexicalEnvironment());
|
||||
addExportEqualsIfNeeded(statements, /*emitAsReturn*/ false);
|
||||
|
||||
const updated = updateSourceFile(node, statements);
|
||||
const updated = updateSourceFileNode(node, createNodeArray(statements, node.statements));
|
||||
if (hasExportStarsToExportValues) {
|
||||
setEmitFlags(updated, EmitFlags.EmitExportStar | getEmitFlags(node));
|
||||
}
|
||||
@ -156,7 +156,8 @@ namespace ts {
|
||||
// Create an updated SourceFile:
|
||||
//
|
||||
// define(moduleName?, ["module1", "module2"], function ...
|
||||
return updateSourceFile(node, [
|
||||
return updateSourceFileNode(node, createNodeArray(
|
||||
[
|
||||
createStatement(
|
||||
createCall(
|
||||
define,
|
||||
@ -184,8 +185,8 @@ namespace ts {
|
||||
/*name*/ undefined,
|
||||
/*typeParameters*/ undefined,
|
||||
[
|
||||
createParameter("require"),
|
||||
createParameter("exports"),
|
||||
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "require"),
|
||||
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "exports"),
|
||||
...importAliasNames
|
||||
],
|
||||
/*type*/ undefined,
|
||||
@ -194,7 +195,9 @@ namespace ts {
|
||||
]
|
||||
)
|
||||
)
|
||||
]);
|
||||
],
|
||||
/*location*/ node.statements)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -988,7 +991,7 @@ namespace ts {
|
||||
function createRequireCall(importNode: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration) {
|
||||
const moduleName = getExternalModuleNameLiteral(importNode, currentSourceFile, host, resolver, compilerOptions);
|
||||
const args: Expression[] = [];
|
||||
if (isDefined(moduleName)) {
|
||||
if (moduleName) {
|
||||
args.push(moduleName);
|
||||
}
|
||||
|
||||
@ -1037,7 +1040,7 @@ namespace ts {
|
||||
for (const amdDependency of node.amdDependencies) {
|
||||
if (amdDependency.name) {
|
||||
aliasedModuleNames.push(createLiteral(amdDependency.path));
|
||||
importAliasNames.push(createParameter(amdDependency.name));
|
||||
importAliasNames.push(createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, amdDependency.name));
|
||||
}
|
||||
else {
|
||||
unaliasedModuleNames.push(createLiteral(amdDependency.path));
|
||||
@ -1055,7 +1058,7 @@ namespace ts {
|
||||
// This is so that when printer will not substitute the identifier
|
||||
setEmitFlags(importAliasName, EmitFlags.NoSubstitution);
|
||||
aliasedModuleNames.push(externalModuleName);
|
||||
importAliasNames.push(createParameter(importAliasName));
|
||||
importAliasNames.push(createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, importAliasName));
|
||||
}
|
||||
else {
|
||||
unaliasedModuleNames.push(externalModuleName);
|
||||
@ -1064,11 +1067,5 @@ namespace ts {
|
||||
|
||||
return { aliasedModuleNames, unaliasedModuleNames, importAliasNames };
|
||||
}
|
||||
|
||||
function updateSourceFile(node: SourceFile, statements: Statement[]) {
|
||||
const updated = getMutableClone(node);
|
||||
updated.statements = createNodeArray(statements, node.statements);
|
||||
return updated;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,8 +114,8 @@ namespace ts {
|
||||
/*name*/ undefined,
|
||||
/*typeParameters*/ undefined,
|
||||
[
|
||||
createParameter(exportFunctionForFile),
|
||||
createParameter(contextObjectForFile)
|
||||
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, exportFunctionForFile),
|
||||
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, contextObjectForFile)
|
||||
],
|
||||
/*type*/ undefined,
|
||||
setEmitFlags(
|
||||
@ -435,7 +435,7 @@ namespace ts {
|
||||
/*asteriskToken*/ undefined,
|
||||
/*name*/ undefined,
|
||||
/*typeParameters*/ undefined,
|
||||
[createParameter(parameterName)],
|
||||
[createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, parameterName)],
|
||||
/*type*/ undefined,
|
||||
createBlock(statements, /*location*/ undefined, /*multiLine*/ true)
|
||||
)
|
||||
@ -771,7 +771,7 @@ namespace ts {
|
||||
return createFor(
|
||||
expressions.length
|
||||
? inlineExpressions(expressions)
|
||||
: <OmittedExpression>createSynthesizedNode(SyntaxKind.OmittedExpression),
|
||||
: createOmittedExpression(),
|
||||
node.condition,
|
||||
node.incrementor,
|
||||
visitNode(node.statement, visitNestedNode, isStatement),
|
||||
@ -806,10 +806,12 @@ namespace ts {
|
||||
function visitForInStatement(node: ForInStatement): ForInStatement {
|
||||
const initializer = node.initializer;
|
||||
if (shouldHoistLoopInitializer(initializer)) {
|
||||
const updated = getMutableClone(node);
|
||||
updated.initializer = transformForBinding(<VariableDeclarationList>initializer);
|
||||
updated.statement = visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock);
|
||||
return updated;
|
||||
return updateForIn(
|
||||
node,
|
||||
transformForBinding(<VariableDeclarationList>initializer),
|
||||
node.expression,
|
||||
visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock)
|
||||
);
|
||||
}
|
||||
else {
|
||||
return visitEachChild(node, visitNestedNode, context);
|
||||
@ -824,10 +826,12 @@ namespace ts {
|
||||
function visitForOfStatement(node: ForOfStatement): ForOfStatement {
|
||||
const initializer = node.initializer;
|
||||
if (shouldHoistLoopInitializer(initializer)) {
|
||||
const updated = getMutableClone(node);
|
||||
updated.initializer = transformForBinding(<VariableDeclarationList>initializer);
|
||||
updated.statement = visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock);
|
||||
return updated;
|
||||
return updateForOf(
|
||||
node,
|
||||
transformForBinding(<VariableDeclarationList>initializer),
|
||||
node.expression,
|
||||
visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock)
|
||||
);
|
||||
}
|
||||
else {
|
||||
return visitEachChild(node, visitNestedNode, context);
|
||||
@ -840,14 +844,12 @@ namespace ts {
|
||||
* @param node The statement to visit.
|
||||
*/
|
||||
function visitDoStatement(node: DoStatement) {
|
||||
const statement = visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock);
|
||||
if (statement !== node.statement) {
|
||||
const updated = getMutableClone(node);
|
||||
updated.statement = statement;
|
||||
return updated;
|
||||
return updateDo(
|
||||
node,
|
||||
visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock),
|
||||
node.expression
|
||||
);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits the body of a WhileStatement to hoist declarations.
|
||||
@ -855,14 +857,12 @@ namespace ts {
|
||||
* @param node The statement to visit.
|
||||
*/
|
||||
function visitWhileStatement(node: WhileStatement) {
|
||||
const statement = visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock);
|
||||
if (statement !== node.statement) {
|
||||
const updated = getMutableClone(node);
|
||||
updated.statement = statement;
|
||||
return updated;
|
||||
return updateWhile(
|
||||
node,
|
||||
node.expression,
|
||||
visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock)
|
||||
);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits the body of a LabeledStatement to hoist declarations.
|
||||
@ -870,13 +870,11 @@ namespace ts {
|
||||
* @param node The statement to visit.
|
||||
*/
|
||||
function visitLabeledStatement(node: LabeledStatement) {
|
||||
const statement = visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock);
|
||||
if (statement !== node.statement) {
|
||||
const updated = getMutableClone(node);
|
||||
updated.statement = statement;
|
||||
return updated;
|
||||
}
|
||||
return node;
|
||||
return updateLabel(
|
||||
node,
|
||||
node.label,
|
||||
visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -885,13 +883,11 @@ namespace ts {
|
||||
* @param node The statement to visit.
|
||||
*/
|
||||
function visitWithStatement(node: WithStatement) {
|
||||
const statement = visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock);
|
||||
if (statement !== node.statement) {
|
||||
const updated = getMutableClone(node);
|
||||
updated.statement = statement;
|
||||
return updated;
|
||||
}
|
||||
return node;
|
||||
return updateWith(
|
||||
node,
|
||||
node.expression,
|
||||
visitNode(node.statement, visitNestedNode, isStatement, /*optional*/ false, liftToBlock)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -900,13 +896,11 @@ namespace ts {
|
||||
* @param node The statement to visit.
|
||||
*/
|
||||
function visitSwitchStatement(node: SwitchStatement) {
|
||||
const caseBlock = visitNode(node.caseBlock, visitNestedNode, isCaseBlock);
|
||||
if (caseBlock !== node.caseBlock) {
|
||||
const updated = getMutableClone(node);
|
||||
updated.caseBlock = caseBlock;
|
||||
return updated;
|
||||
}
|
||||
return node;
|
||||
return updateSwitch(
|
||||
node,
|
||||
node.expression,
|
||||
visitNode(node.caseBlock, visitNestedNode, isCaseBlock)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -915,13 +909,10 @@ namespace ts {
|
||||
* @param node The node to visit.
|
||||
*/
|
||||
function visitCaseBlock(node: CaseBlock) {
|
||||
const clauses = visitNodes(node.clauses, visitNestedNode, isCaseOrDefaultClause);
|
||||
if (clauses !== node.clauses) {
|
||||
const updated = getMutableClone(node);
|
||||
updated.clauses = clauses;
|
||||
return updated;
|
||||
}
|
||||
return node;
|
||||
return updateCaseBlock(
|
||||
node,
|
||||
visitNodes(node.clauses, visitNestedNode, isCaseOrDefaultClause)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -930,13 +921,11 @@ namespace ts {
|
||||
* @param node The clause to visit.
|
||||
*/
|
||||
function visitCaseClause(node: CaseClause) {
|
||||
const statements = visitNodes(node.statements, visitNestedNode, isStatement);
|
||||
if (statements !== node.statements) {
|
||||
const updated = getMutableClone(node);
|
||||
updated.statements = statements;
|
||||
return updated;
|
||||
}
|
||||
return node;
|
||||
return updateCaseClause(
|
||||
node,
|
||||
node.expression,
|
||||
visitNodes(node.statements, visitNestedNode, isStatement)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -963,13 +952,11 @@ namespace ts {
|
||||
* @param node The clause to visit.
|
||||
*/
|
||||
function visitCatchClause(node: CatchClause) {
|
||||
const block = visitNode(node.block, visitNestedNode, isBlock);
|
||||
if (block !== node.block) {
|
||||
const updated = getMutableClone(node);
|
||||
updated.block = block;
|
||||
return updated;
|
||||
}
|
||||
return node;
|
||||
return updateCatchClause(
|
||||
node,
|
||||
node.variableDeclaration,
|
||||
visitNode(node.block, visitNestedNode, isBlock)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1223,7 +1210,7 @@ namespace ts {
|
||||
/*asteriskToken*/ undefined,
|
||||
exportStarFunction,
|
||||
/*typeParameters*/ undefined,
|
||||
[createParameter(m)],
|
||||
[createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, m)],
|
||||
/*type*/ undefined,
|
||||
createBlock([
|
||||
createVariableStatement(
|
||||
|
||||
@ -48,7 +48,7 @@ namespace ts {
|
||||
let currentNamespaceContainerName: Identifier;
|
||||
let currentScope: SourceFile | Block | ModuleBlock | CaseBlock;
|
||||
let currentScopeFirstDeclarationsOfName: Map<Node>;
|
||||
let currentSourceFileExternalHelpersModuleName: Identifier;
|
||||
let currentExternalHelpersModuleName: Identifier;
|
||||
|
||||
/**
|
||||
* Keeps track of whether expression substitution has been enabled for specific edge cases.
|
||||
@ -475,16 +475,16 @@ namespace ts {
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
createImportClause(/*name*/ undefined, createNamespaceImport(externalHelpersModuleName)),
|
||||
createLiteral(externalHelpersModuleNameText)
|
||||
);
|
||||
createLiteral(externalHelpersModuleNameText));
|
||||
|
||||
externalHelpersModuleImport.parent = node;
|
||||
externalHelpersModuleImport.flags &= ~NodeFlags.Synthesized;
|
||||
statements.push(externalHelpersModuleImport);
|
||||
|
||||
currentSourceFileExternalHelpersModuleName = externalHelpersModuleName;
|
||||
currentExternalHelpersModuleName = externalHelpersModuleName;
|
||||
addRange(statements, visitNodes(node.statements, sourceElementVisitor, isStatement, statementOffset));
|
||||
addRange(statements, endLexicalEnvironment());
|
||||
currentSourceFileExternalHelpersModuleName = undefined;
|
||||
currentExternalHelpersModuleName = undefined;
|
||||
|
||||
node = updateSourceFileNode(node, createNodeArray(statements, node.statements));
|
||||
node.externalHelpersModuleName = externalHelpersModuleName;
|
||||
@ -614,9 +614,10 @@ namespace ts {
|
||||
* Transforms a decorated class declaration and appends the resulting statements. If
|
||||
* the class requires an alias to avoid issues with double-binding, the alias is returned.
|
||||
*
|
||||
* @param statements A statement list to which to add the declaration.
|
||||
* @param node A ClassDeclaration node.
|
||||
* @param name The name of the class.
|
||||
* @param hasExtendsClause A value indicating whether
|
||||
* @param hasExtendsClause A value indicating whether the class has an extends clause.
|
||||
*/
|
||||
function addClassDeclarationHeadWithDecorators(statements: Statement[], node: ClassDeclaration, name: Identifier, hasExtendsClause: boolean) {
|
||||
// When we emit an ES6 class that has a class decorator, we must tailor the
|
||||
@ -1454,7 +1455,7 @@ namespace ts {
|
||||
: undefined;
|
||||
|
||||
const helper = createDecorateHelper(
|
||||
currentSourceFileExternalHelpersModuleName,
|
||||
currentExternalHelpersModuleName,
|
||||
decoratorExpressions,
|
||||
prefix,
|
||||
memberName,
|
||||
@ -1504,7 +1505,7 @@ namespace ts {
|
||||
const expression = createAssignment(
|
||||
decoratedClassAlias,
|
||||
createDecorateHelper(
|
||||
currentSourceFileExternalHelpersModuleName,
|
||||
currentExternalHelpersModuleName,
|
||||
decoratorExpressions,
|
||||
getDeclarationName(node)
|
||||
)
|
||||
@ -1528,7 +1529,7 @@ namespace ts {
|
||||
const result = createAssignment(
|
||||
getDeclarationName(node),
|
||||
createDecorateHelper(
|
||||
currentSourceFileExternalHelpersModuleName,
|
||||
currentExternalHelpersModuleName,
|
||||
decoratorExpressions,
|
||||
getDeclarationName(node)
|
||||
),
|
||||
@ -1561,7 +1562,7 @@ namespace ts {
|
||||
expressions = [];
|
||||
for (const decorator of decorators) {
|
||||
const helper = createParamHelper(
|
||||
currentSourceFileExternalHelpersModuleName,
|
||||
currentExternalHelpersModuleName,
|
||||
transformDecorator(decorator),
|
||||
parameterOffset,
|
||||
/*location*/ decorator.expression);
|
||||
@ -1591,13 +1592,13 @@ namespace ts {
|
||||
function addOldTypeMetadata(node: Declaration, decoratorExpressions: Expression[]) {
|
||||
if (compilerOptions.emitDecoratorMetadata) {
|
||||
if (shouldAddTypeMetadata(node)) {
|
||||
decoratorExpressions.push(createMetadataHelper(currentSourceFileExternalHelpersModuleName, "design:type", serializeTypeOfNode(node)));
|
||||
decoratorExpressions.push(createMetadataHelper(currentExternalHelpersModuleName, "design:type", serializeTypeOfNode(node)));
|
||||
}
|
||||
if (shouldAddParamTypesMetadata(node)) {
|
||||
decoratorExpressions.push(createMetadataHelper(currentSourceFileExternalHelpersModuleName, "design:paramtypes", serializeParameterTypesOfNode(node)));
|
||||
decoratorExpressions.push(createMetadataHelper(currentExternalHelpersModuleName, "design:paramtypes", serializeParameterTypesOfNode(node)));
|
||||
}
|
||||
if (shouldAddReturnTypeMetadata(node)) {
|
||||
decoratorExpressions.push(createMetadataHelper(currentSourceFileExternalHelpersModuleName, "design:returntype", serializeReturnTypeOfNode(node)));
|
||||
decoratorExpressions.push(createMetadataHelper(currentExternalHelpersModuleName, "design:returntype", serializeReturnTypeOfNode(node)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1606,16 +1607,16 @@ namespace ts {
|
||||
if (compilerOptions.emitDecoratorMetadata) {
|
||||
let properties: ObjectLiteralElementLike[];
|
||||
if (shouldAddTypeMetadata(node)) {
|
||||
(properties || (properties = [])).push(createPropertyAssignment("type", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, /*equalsGreaterThanToken*/ undefined, serializeTypeOfNode(node))));
|
||||
(properties || (properties = [])).push(createPropertyAssignment("type", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), serializeTypeOfNode(node))));
|
||||
}
|
||||
if (shouldAddParamTypesMetadata(node)) {
|
||||
(properties || (properties = [])).push(createPropertyAssignment("paramTypes", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, /*equalsGreaterThanToken*/ undefined, serializeParameterTypesOfNode(node))));
|
||||
(properties || (properties = [])).push(createPropertyAssignment("paramTypes", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), serializeParameterTypesOfNode(node))));
|
||||
}
|
||||
if (shouldAddReturnTypeMetadata(node)) {
|
||||
(properties || (properties = [])).push(createPropertyAssignment("returnType", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, /*equalsGreaterThanToken*/ undefined, serializeReturnTypeOfNode(node))));
|
||||
(properties || (properties = [])).push(createPropertyAssignment("returnType", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), serializeReturnTypeOfNode(node))));
|
||||
}
|
||||
if (properties) {
|
||||
decoratorExpressions.push(createMetadataHelper(currentSourceFileExternalHelpersModuleName, "design:typeinfo", createObjectLiteral(properties, /*location*/ undefined, /*multiLine*/ true)));
|
||||
decoratorExpressions.push(createMetadataHelper(currentExternalHelpersModuleName, "design:typeinfo", createObjectLiteral(properties, /*location*/ undefined, /*multiLine*/ true)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2188,9 +2189,9 @@ namespace ts {
|
||||
|
||||
// While we emit the source map for the node after skipping decorators and modifiers,
|
||||
// we need to emit the comments for the original range.
|
||||
setOriginalNode(accessor, node);
|
||||
setCommentRange(accessor, node);
|
||||
setSourceMapRange(accessor, moveRangePastDecorators(node));
|
||||
setOriginalNode(accessor, node);
|
||||
|
||||
return accessor;
|
||||
}
|
||||
@ -2220,9 +2221,9 @@ namespace ts {
|
||||
|
||||
// While we emit the source map for the node after skipping decorators and modifiers,
|
||||
// we need to emit the comments for the original range.
|
||||
setOriginalNode(accessor, node);
|
||||
setCommentRange(accessor, node);
|
||||
setSourceMapRange(accessor, moveRangePastDecorators(node));
|
||||
setOriginalNode(accessor, node);
|
||||
|
||||
return accessor;
|
||||
}
|
||||
@ -2372,7 +2373,7 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const parameter = createParameterDeclaration(
|
||||
const parameter = createParameter(
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
node.dotDotDotToken,
|
||||
@ -2590,7 +2591,7 @@ namespace ts {
|
||||
/*asteriskToken*/ undefined,
|
||||
/*name*/ undefined,
|
||||
/*typeParameters*/ undefined,
|
||||
[createParameter(parameterName)],
|
||||
[createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, parameterName)],
|
||||
/*type*/ undefined,
|
||||
transformEnumBody(node, containerName)
|
||||
),
|
||||
@ -2758,7 +2759,7 @@ namespace ts {
|
||||
]
|
||||
);
|
||||
|
||||
setOriginalNode(statement, /*original*/ node);
|
||||
setOriginalNode(statement, node);
|
||||
|
||||
// Adjust the source map emit to match the old emitter.
|
||||
if (node.kind === SyntaxKind.EnumDeclaration) {
|
||||
@ -2862,7 +2863,7 @@ namespace ts {
|
||||
/*asteriskToken*/ undefined,
|
||||
/*name*/ undefined,
|
||||
/*typeParameters*/ undefined,
|
||||
[createParameter(parameterName)],
|
||||
[createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, parameterName)],
|
||||
/*type*/ undefined,
|
||||
transformModuleBody(node, containerName)
|
||||
),
|
||||
@ -3387,6 +3388,7 @@ namespace ts {
|
||||
/**
|
||||
* Hook for node emit.
|
||||
*
|
||||
* @param emitContext A context hint for the emitter.
|
||||
* @param node The node to emit.
|
||||
* @param emit A callback used to emit the node in the printer.
|
||||
*/
|
||||
@ -3409,9 +3411,8 @@ namespace ts {
|
||||
/**
|
||||
* Hooks node substitutions.
|
||||
*
|
||||
* @param emitContext A context hint for the emitter.
|
||||
* @param node The node to substitute.
|
||||
* @param isExpression A value indicating whether the node is to be used in an expression
|
||||
* position.
|
||||
*/
|
||||
function onSubstituteNode(emitContext: EmitContext, node: Node) {
|
||||
node = previousOnSubstituteNode(emitContext, node);
|
||||
|
||||
@ -552,6 +552,14 @@ namespace ts {
|
||||
resolvedSymbol: Symbol;
|
||||
}
|
||||
|
||||
/*@internal*/
|
||||
export interface GeneratedIdentifier extends Identifier {
|
||||
autoGenerateKind: GeneratedIdentifierKind.Auto
|
||||
| GeneratedIdentifierKind.Loop
|
||||
| GeneratedIdentifierKind.Unique
|
||||
| GeneratedIdentifierKind.Node;
|
||||
}
|
||||
|
||||
export interface QualifiedName extends Node {
|
||||
kind: SyntaxKind.QualifiedName;
|
||||
left: EntityName;
|
||||
|
||||
@ -3646,7 +3646,7 @@ namespace ts {
|
||||
return node.kind === SyntaxKind.Identifier;
|
||||
}
|
||||
|
||||
export function isGeneratedIdentifier(node: Node): boolean {
|
||||
export function isGeneratedIdentifier(node: Node): node is GeneratedIdentifier {
|
||||
// Using `>` here catches both `GeneratedIdentifierKind.None` and `undefined`.
|
||||
return isIdentifier(node) && node.autoGenerateKind > GeneratedIdentifierKind.None;
|
||||
}
|
||||
|
||||
@ -692,7 +692,7 @@ namespace ts {
|
||||
|
||||
// Signature elements
|
||||
case SyntaxKind.Parameter:
|
||||
return updateParameterDeclaration(<ParameterDeclaration>node,
|
||||
return updateParameter(<ParameterDeclaration>node,
|
||||
visitNodes((<ParameterDeclaration>node).decorators, visitor, isDecorator),
|
||||
visitNodes((<ParameterDeclaration>node).modifiers, visitor, isModifier),
|
||||
visitNode((<ParameterDeclaration>node).name, visitor, isBindingName),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user