Skip to content

Commit f025e0c

Browse files
committed
Minor cleanup
1 parent e97368b commit f025e0c

File tree

9 files changed

+136
-162
lines changed

9 files changed

+136
-162
lines changed

src/compiler/factory.ts

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ namespace ts {
109109
export function createLiteral(value: string | number | boolean, location?: TextRange): PrimaryExpression;
110110
export function createLiteral(value: string | number | boolean | StringLiteral | Identifier, location?: TextRange): PrimaryExpression {
111111
if (typeof value === "number") {
112-
const node = <LiteralExpression>createNode(SyntaxKind.NumericLiteral, location, /*flags*/ undefined);
112+
const node = <NumericLiteral>createNode(SyntaxKind.NumericLiteral, location, /*flags*/ undefined);
113113
node.text = value.toString();
114114
return node;
115115
}
116116
else if (typeof value === "boolean") {
117-
return <PrimaryExpression>createNode(value ? SyntaxKind.TrueKeyword : SyntaxKind.FalseKeyword, location, /*flags*/ undefined);
117+
return <BooleanLiteral>createNode(value ? SyntaxKind.TrueKeyword : SyntaxKind.FalseKeyword, location, /*flags*/ undefined);
118118
}
119119
else if (typeof value === "string") {
120120
const node = <StringLiteral>createNode(SyntaxKind.StringLiteral, location, /*flags*/ undefined);
@@ -226,20 +226,7 @@ namespace ts {
226226

227227
// Signature elements
228228

229-
export function createParameter(name: string | Identifier | BindingPattern, initializer?: Expression, location?: TextRange) {
230-
return createParameterDeclaration(
231-
/*decorators*/ undefined,
232-
/*modifiers*/ undefined,
233-
/*dotDotDotToken*/ undefined,
234-
name,
235-
/*questionToken*/ undefined,
236-
/*type*/ undefined,
237-
initializer,
238-
location
239-
);
240-
}
241-
242-
export function createParameterDeclaration(decorators: Decorator[], modifiers: Modifier[], dotDotDotToken: DotDotDotToken, name: string | Identifier | BindingPattern, questionToken: QuestionToken, type: TypeNode, initializer: Expression, location?: TextRange, flags?: NodeFlags) {
229+
export function createParameter(decorators: Decorator[], modifiers: Modifier[], dotDotDotToken: DotDotDotToken, name: string | Identifier | BindingPattern, questionToken?: QuestionToken, type?: TypeNode, initializer?: Expression, location?: TextRange, flags?: NodeFlags) {
243230
const node = <ParameterDeclaration>createNode(SyntaxKind.Parameter, location, flags);
244231
node.decorators = decorators ? createNodeArray(decorators) : undefined;
245232
node.modifiers = modifiers ? createNodeArray(modifiers) : undefined;
@@ -251,9 +238,9 @@ namespace ts {
251238
return node;
252239
}
253240

254-
export function updateParameterDeclaration(node: ParameterDeclaration, decorators: Decorator[], modifiers: Modifier[], name: BindingName, type: TypeNode, initializer: Expression) {
241+
export function updateParameter(node: ParameterDeclaration, decorators: Decorator[], modifiers: Modifier[], name: BindingName, type: TypeNode, initializer: Expression) {
255242
if (node.decorators !== decorators || node.modifiers !== modifiers || node.name !== name || node.type !== type || node.initializer !== initializer) {
256-
return updateNode(createParameterDeclaration(decorators, modifiers, node.dotDotDotToken, name, node.questionToken, type, initializer, /*location*/ node, /*flags*/ node.flags), node);
243+
return updateNode(createParameter(decorators, modifiers, node.dotDotDotToken, name, node.questionToken, type, initializer, /*location*/ node, /*flags*/ node.flags), node);
257244
}
258245

259246
return node;
@@ -1557,18 +1544,6 @@ namespace ts {
15571544
}
15581545
}
15591546

1560-
export function createRestParameter(name: string | Identifier) {
1561-
return createParameterDeclaration(
1562-
/*decorators*/ undefined,
1563-
/*modifiers*/ undefined,
1564-
createToken(SyntaxKind.DotDotDotToken),
1565-
name,
1566-
/*questionToken*/ undefined,
1567-
/*type*/ undefined,
1568-
/*initializer*/ undefined
1569-
);
1570-
}
1571-
15721547
export function createFunctionCall(func: Expression, thisArg: Expression, argumentsList: Expression[], location?: TextRange) {
15731548
return createCall(
15741549
createPropertyAccess(func, "call"),
@@ -1781,13 +1756,10 @@ namespace ts {
17811756
return createArrowFunction(
17821757
/*modifiers*/ undefined,
17831758
/*typeParameters*/ undefined,
1784-
[createParameter("name")],
1759+
[createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "name")],
17851760
/*type*/ undefined,
1786-
/*equalsGreaterThanToken*/ undefined,
1787-
createElementAccess(
1788-
target,
1789-
createIdentifier("name")
1790-
)
1761+
createToken(SyntaxKind.EqualsGreaterThanToken),
1762+
createElementAccess(target, createIdentifier("name"))
17911763
);
17921764
}
17931765

@@ -1797,11 +1769,11 @@ namespace ts {
17971769
/*modifiers*/ undefined,
17981770
/*typeParameters*/ undefined,
17991771
[
1800-
createParameter("name"),
1801-
createParameter("value")
1772+
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "name"),
1773+
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "value")
18021774
],
18031775
/*type*/ undefined,
1804-
/*equalsGreaterThanToken*/ undefined,
1776+
createToken(SyntaxKind.EqualsGreaterThanToken),
18051777
createAssignment(
18061778
createElementAccess(
18071779
target,
@@ -1853,7 +1825,7 @@ namespace ts {
18531825
/*decorators*/ undefined,
18541826
/*modifiers*/ undefined,
18551827
"value",
1856-
[createParameter("v")],
1828+
[createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "v")],
18571829
createBlock([
18581830
createStatement(
18591831
createCall(
@@ -1873,9 +1845,9 @@ namespace ts {
18731845
createArrowFunction(
18741846
/*modifiers*/ undefined,
18751847
/*typeParameters*/ undefined,
1876-
[createParameter("name")],
1848+
[createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "name")],
18771849
/*type*/ undefined,
1878-
/*equalsGreaterThanToken*/ undefined,
1850+
createToken(SyntaxKind.EqualsGreaterThanToken),
18791851
createLogicalOr(
18801852
createElementAccess(
18811853
createIdentifier("cache"),
@@ -1915,8 +1887,8 @@ namespace ts {
19151887
/*name*/ undefined,
19161888
/*typeParameters*/ undefined,
19171889
[
1918-
createParameter("geti"),
1919-
createParameter("seti")
1890+
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "geti"),
1891+
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "seti")
19201892
],
19211893
/*type*/ undefined,
19221894
createBlock([
@@ -2246,7 +2218,7 @@ namespace ts {
22462218

22472219
/**
22482220
* Ensures "use strict" directive is added
2249-
*
2221+
*
22502222
* @param node source file
22512223
*/
22522224
export function ensureUseStrict(node: SourceFile): SourceFile {

src/compiler/transformers/es2015.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ namespace ts {
685685
/*asteriskToken*/ undefined,
686686
/*name*/ undefined,
687687
/*typeParameters*/ undefined,
688-
extendsClauseElement ? [createParameter("_super")] : [],
688+
extendsClauseElement ? [createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "_super")] : [],
689689
/*type*/ undefined,
690690
transformClassBody(node, extendsClauseElement)
691691
);
@@ -1035,7 +1035,12 @@ namespace ts {
10351035
// evaluated inside the function body.
10361036
return setOriginalNode(
10371037
createParameter(
1038+
/*decorators*/ undefined,
1039+
/*modifiers*/ undefined,
1040+
/*dotDotDotToken*/ undefined,
10381041
getGeneratedNameForNode(node),
1042+
/*questionToken*/ undefined,
1043+
/*type*/ undefined,
10391044
/*initializer*/ undefined,
10401045
/*location*/ node
10411046
),
@@ -1046,7 +1051,12 @@ namespace ts {
10461051
// Initializers are elided
10471052
return setOriginalNode(
10481053
createParameter(
1054+
/*decorators*/ undefined,
1055+
/*modifiers*/ undefined,
1056+
/*dotDotDotToken*/ undefined,
10491057
node.name,
1058+
/*questionToken*/ undefined,
1059+
/*type*/ undefined,
10501060
/*initializer*/ undefined,
10511061
/*location*/ node
10521062
),
@@ -2506,7 +2516,7 @@ namespace ts {
25062516
}
25072517
}
25082518
else {
2509-
loopParameters.push(createParameter(name));
2519+
loopParameters.push(createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, name));
25102520
if (resolver.getNodeCheckFlags(decl) & NodeCheckFlags.NeedsLoopOutParameter) {
25112521
const outParamName = createUniqueName("out_" + name.text);
25122522
loopOutParameters.push({ originalName: name, outParamName });
@@ -3081,9 +3091,8 @@ namespace ts {
30813091
/**
30823092
* Hooks node substitutions.
30833093
*
3094+
* @param emitContext The context for the emitter.
30843095
* @param node The node to substitute.
3085-
* @param isExpression A value indicating whether the node is to be used in an expression
3086-
* position.
30873096
*/
30883097
function onSubstituteNode(emitContext: EmitContext, node: Node) {
30893098
node = previousOnSubstituteNode(emitContext, node);

src/compiler/transformers/generators.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,7 +2369,7 @@ namespace ts {
23692369
labelExpressions = [];
23702370
}
23712371

2372-
const expression = <LiteralExpression>createSynthesizedNode(SyntaxKind.NumericLiteral);
2372+
const expression = createLiteral(-1);
23732373
if (labelExpressions[label] === undefined) {
23742374
labelExpressions[label] = [expression];
23752375
}
@@ -2380,7 +2380,7 @@ namespace ts {
23802380
return expression;
23812381
}
23822382

2383-
return <OmittedExpression>createNode(SyntaxKind.OmittedExpression);
2383+
return createOmittedExpression();
23842384
}
23852385

23862386
/**
@@ -2596,7 +2596,7 @@ namespace ts {
25962596
/*asteriskToken*/ undefined,
25972597
/*name*/ undefined,
25982598
/*typeParameters*/ undefined,
2599-
[createParameter(state)],
2599+
[createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, state)],
26002600
/*type*/ undefined,
26012601
createBlock(
26022602
buildResult,

src/compiler/transformers/module/module.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ namespace ts {
9191
addRange(statements, endLexicalEnvironment());
9292
addExportEqualsIfNeeded(statements, /*emitAsReturn*/ false);
9393

94-
const updated = updateSourceFile(node, statements);
94+
const updated = updateSourceFileNode(node, createNodeArray(statements, node.statements));
9595
if (hasExportStarsToExportValues) {
9696
setEmitFlags(updated, EmitFlags.EmitExportStar | getEmitFlags(node));
9797
}
@@ -156,7 +156,8 @@ namespace ts {
156156
// Create an updated SourceFile:
157157
//
158158
// define(moduleName?, ["module1", "module2"], function ...
159-
return updateSourceFile(node, [
159+
return updateSourceFileNode(node, createNodeArray(
160+
[
160161
createStatement(
161162
createCall(
162163
define,
@@ -184,8 +185,8 @@ namespace ts {
184185
/*name*/ undefined,
185186
/*typeParameters*/ undefined,
186187
[
187-
createParameter("require"),
188-
createParameter("exports"),
188+
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "require"),
189+
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "exports"),
189190
...importAliasNames
190191
],
191192
/*type*/ undefined,
@@ -194,7 +195,9 @@ namespace ts {
194195
]
195196
)
196197
)
197-
]);
198+
],
199+
/*location*/ node.statements)
200+
);
198201
}
199202

200203
/**
@@ -988,7 +991,7 @@ namespace ts {
988991
function createRequireCall(importNode: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration) {
989992
const moduleName = getExternalModuleNameLiteral(importNode, currentSourceFile, host, resolver, compilerOptions);
990993
const args: Expression[] = [];
991-
if (isDefined(moduleName)) {
994+
if (moduleName) {
992995
args.push(moduleName);
993996
}
994997

@@ -1037,7 +1040,7 @@ namespace ts {
10371040
for (const amdDependency of node.amdDependencies) {
10381041
if (amdDependency.name) {
10391042
aliasedModuleNames.push(createLiteral(amdDependency.path));
1040-
importAliasNames.push(createParameter(amdDependency.name));
1043+
importAliasNames.push(createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, amdDependency.name));
10411044
}
10421045
else {
10431046
unaliasedModuleNames.push(createLiteral(amdDependency.path));
@@ -1055,7 +1058,7 @@ namespace ts {
10551058
// This is so that when printer will not substitute the identifier
10561059
setEmitFlags(importAliasName, EmitFlags.NoSubstitution);
10571060
aliasedModuleNames.push(externalModuleName);
1058-
importAliasNames.push(createParameter(importAliasName));
1061+
importAliasNames.push(createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, importAliasName));
10591062
}
10601063
else {
10611064
unaliasedModuleNames.push(externalModuleName);
@@ -1064,11 +1067,5 @@ namespace ts {
10641067

10651068
return { aliasedModuleNames, unaliasedModuleNames, importAliasNames };
10661069
}
1067-
1068-
function updateSourceFile(node: SourceFile, statements: Statement[]) {
1069-
const updated = getMutableClone(node);
1070-
updated.statements = createNodeArray(statements, node.statements);
1071-
return updated;
1072-
}
10731070
}
10741071
}

0 commit comments

Comments
 (0)