Skip to content

Remove duplication from transformers #29871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace ts {

addRange(transformers, customTransformers && customTransformers.after);

return transformers;
return map(transformers, (tf: TransformerFactory<SourceFile>) => (context: TransformationContext) => chainBundle(tf(context)));
}

export function noEmitSubstitution(_hint: EmitHint, node: Node) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/es2015.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ namespace ts {
*/
let enabledSubstitutions: ES2015SubstitutionFlags;

return chainBundle(transformSourceFile);
return transformSourceFile;

function transformSourceFile(node: SourceFile) {
if (node.isDeclarationFile) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/es2016.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace ts {
export function transformES2016(context: TransformationContext) {
const { hoistVariableDeclaration } = context;

return chainBundle(transformSourceFile);
return transformSourceFile;

function transformSourceFile(node: SourceFile) {
if (node.isDeclarationFile) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/es2017.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace ts {
context.onEmitNode = onEmitNode;
context.onSubstituteNode = onSubstituteNode;

return chainBundle(transformSourceFile);
return transformSourceFile;

function transformSourceFile(node: SourceFile) {
if (node.isDeclarationFile) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/es2018.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace ts {
/** A set of node IDs for generated super accessors. */
const substitutedSuperAccessors: boolean[] = [];

return chainBundle(transformSourceFile);
return transformSourceFile;

function transformSourceFile(node: SourceFile) {
if (node.isDeclarationFile) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/es2019.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*@internal*/
namespace ts {
export function transformES2019(context: TransformationContext) {
return chainBundle(transformSourceFile);
return transformSourceFile;

function transformSourceFile(node: SourceFile) {
if (node.isDeclarationFile) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/es5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace ts {
context.onSubstituteNode = onSubstituteNode;
context.enableSubstitution(SyntaxKind.PropertyAccessExpression);
context.enableSubstitution(SyntaxKind.PropertyAssignment);
return chainBundle(transformSourceFile);
return transformSourceFile;

/**
* Transforms an ES5 source file to ES3.
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/esnext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*@internal*/
namespace ts {
export function transformESNext(context: TransformationContext) {
return chainBundle(transformSourceFile);
return transformSourceFile;

function transformSourceFile(node: SourceFile) {
if (node.isDeclarationFile) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ namespace ts {
let currentExceptionBlock: ExceptionBlock | undefined; // The current exception block.
let withBlockStack: WithBlock[] | undefined; // A stack containing `with` blocks.

return chainBundle(transformSourceFile);
return transformSourceFile;

function transformSourceFile(node: SourceFile) {
if (node.isDeclarationFile || (node.transformFlags & TransformFlags.ContainsGenerator) === 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace ts {
const compilerOptions = context.getCompilerOptions();
let currentSourceFile: SourceFile;

return chainBundle(transformSourceFile);
return transformSourceFile;

/**
* Transform JSX-specific syntax in a SourceFile.
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/module/es2015.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace ts {
context.enableSubstitution(SyntaxKind.Identifier);

let currentSourceFile: SourceFile | undefined;
return chainBundle(transformSourceFile);
return transformSourceFile;

function transformSourceFile(node: SourceFile) {
if (node.isDeclarationFile) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/module/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace ts {
let noSubstitution: boolean[]; // Set of nodes for which substitution rules should be ignored.
let needUMDDynamicImportHelper: boolean;

return chainBundle(transformSourceFile);
return transformSourceFile;

/**
* Transforms the module aspects of a SourceFile.
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/module/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace ts {
let enclosingBlockScopedContainer: Node;
let noSubstitution: boolean[] | undefined; // Set of nodes for which substitution rules should be ignored.

return chainBundle(transformSourceFile);
return transformSourceFile;

/**
* Transforms the module aspects of a SourceFile.
Expand Down
18 changes: 1 addition & 17 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,7 @@ namespace ts {
*/
let pendingExpressions: Expression[] | undefined;

return transformSourceFileOrBundle;

function transformSourceFileOrBundle(node: SourceFile | Bundle) {
if (node.kind === SyntaxKind.Bundle) {
return transformBundle(node);
}
return transformSourceFile(node);
}

function transformBundle(node: Bundle) {
return createBundle(node.sourceFiles.map(transformSourceFile), mapDefined(node.prepends, prepend => {
if (prepend.kind === SyntaxKind.InputFiles) {
return createUnparsedSourceFile(prepend, "js");
}
return prepend;
}));
}
return transformSourceFile;

/**
* Transform TypeScript-specific syntax in a SourceFile.
Expand Down
9 changes: 7 additions & 2 deletions src/compiler/transformers/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ namespace ts {
}

function transformBundle(node: Bundle) {
return createBundle(map(node.sourceFiles, transformSourceFile), node.prepends);
return createBundle(node.sourceFiles.map(transformSourceFile), mapDefined(node.prepends, prepend => {
if (prepend.kind === SyntaxKind.InputFiles) {
return createUnparsedSourceFile(prepend, "js");
}
return prepend;
}));
}
}

Expand Down Expand Up @@ -255,4 +260,4 @@ namespace ts {
return result;
};
}
}
}