Removes 'TypeScript' transform flag
This commit is contained in:
parent
5576c3ead8
commit
ad4cef01a3
|
@ -208,15 +208,9 @@ namespace ts {
|
|||
* @param node The node to visit.
|
||||
*/
|
||||
function visitorWorker(node: Node): VisitResult<Node> {
|
||||
if (node.transformFlags & TransformFlags.TypeScript) {
|
||||
// This node is explicitly marked as TypeScript, so we should transform the node.
|
||||
if (node.transformFlags & TransformFlags.ContainsTypeScript) {
|
||||
return visitTypeScript(node);
|
||||
}
|
||||
else if (node.transformFlags & TransformFlags.ContainsTypeScript) {
|
||||
// This node contains TypeScript, so we should visit its children.
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
@ -296,15 +290,9 @@ namespace ts {
|
|||
(<ImportEqualsDeclaration>node).moduleReference.kind === SyntaxKind.ExternalModuleReference)) {
|
||||
// do not emit ES6 imports and exports since they are illegal inside a namespace
|
||||
return undefined;
|
||||
}
|
||||
else if (node.transformFlags & TransformFlags.TypeScript || hasModifier(node, ModifierFlags.Export)) {
|
||||
// This node is explicitly marked as TypeScript, or is exported at the namespace
|
||||
// level, so we should transform the node.
|
||||
return visitTypeScript(node);
|
||||
}
|
||||
else if (node.transformFlags & TransformFlags.ContainsTypeScript) {
|
||||
// This node contains TypeScript, so we should visit its children.
|
||||
return visitEachChild(node, visitor, context);
|
||||
else if (node.transformFlags & TransformFlags.ContainsTypeScript || hasModifier(node, ModifierFlags.Export)) {
|
||||
return visitTypeScript(node);
|
||||
}
|
||||
|
||||
return node;
|
||||
|
@ -365,7 +353,7 @@ namespace ts {
|
|||
* @param node The node to visit.
|
||||
*/
|
||||
function visitTypeScript(node: Node): VisitResult<Node> {
|
||||
if (hasModifier(node, ModifierFlags.Ambient) && isStatement(node)) {
|
||||
if (isStatement(node) && hasModifier(node, ModifierFlags.Ambient)) {
|
||||
// TypeScript ambient declarations are elided, but some comments may be preserved.
|
||||
// See the implementation of `getLeadingComments` in comments.ts for more details.
|
||||
return createNotEmittedStatement(node);
|
||||
|
@ -443,7 +431,7 @@ namespace ts {
|
|||
return createNotEmittedStatement(node);
|
||||
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
// This is a class declaration with TypeScript syntax extensions.
|
||||
// This may be a class declaration with TypeScript syntax extensions.
|
||||
//
|
||||
// TypeScript class syntax extensions include:
|
||||
// - decorators
|
||||
|
@ -455,7 +443,7 @@ namespace ts {
|
|||
return visitClassDeclaration(<ClassDeclaration>node);
|
||||
|
||||
case SyntaxKind.ClassExpression:
|
||||
// This is a class expression with TypeScript syntax extensions.
|
||||
// This may be a class expression with TypeScript syntax extensions.
|
||||
//
|
||||
// TypeScript class syntax extensions include:
|
||||
// - decorators
|
||||
|
@ -467,7 +455,7 @@ namespace ts {
|
|||
return visitClassExpression(<ClassExpression>node);
|
||||
|
||||
case SyntaxKind.HeritageClause:
|
||||
// This is a heritage clause with TypeScript syntax extensions.
|
||||
// This may be a heritage clause with TypeScript syntax extensions.
|
||||
//
|
||||
// TypeScript heritage clause extensions include:
|
||||
// - `implements` clause
|
||||
|
@ -503,7 +491,7 @@ namespace ts {
|
|||
return visitArrowFunction(<ArrowFunction>node);
|
||||
|
||||
case SyntaxKind.Parameter:
|
||||
// This is a parameter declaration with TypeScript syntax extensions.
|
||||
// This may be a parameter declaration with TypeScript syntax extensions.
|
||||
//
|
||||
// TypeScript parameter declaration syntax extensions include:
|
||||
// - decorators
|
||||
|
@ -556,7 +544,8 @@ namespace ts {
|
|||
return visitImportEqualsDeclaration(<ImportEqualsDeclaration>node);
|
||||
|
||||
default:
|
||||
return Debug.failBadSyntaxKind(node);
|
||||
// node contains some other TypeScript syntax
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -607,18 +596,22 @@ namespace ts {
|
|||
return facts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a class declaration with TypeScript syntax into compatible ES6.
|
||||
*
|
||||
* This function will only be called when one of the following conditions are met:
|
||||
* - The class has decorators.
|
||||
* - The class has property declarations with initializers.
|
||||
* - The class contains a constructor that contains parameters with accessibility modifiers.
|
||||
* - The class is an export in a TypeScript namespace.
|
||||
*
|
||||
* @param node The node to transform.
|
||||
*/
|
||||
function hasTypeScriptClassSyntax(node: Node) {
|
||||
return !!(node.transformFlags & TransformFlags.ContainsTypeScriptClassSyntax);
|
||||
}
|
||||
|
||||
function isClassLikeDeclarationWithTypeScriptSyntax(node: ClassLikeDeclaration) {
|
||||
return some(node.decorators)
|
||||
|| some(node.typeParameters)
|
||||
|| some(node.heritageClauses, hasTypeScriptClassSyntax)
|
||||
|| some(node.members, hasTypeScriptClassSyntax);
|
||||
}
|
||||
|
||||
function visitClassDeclaration(node: ClassDeclaration): VisitResult<Statement> {
|
||||
if (!isClassLikeDeclarationWithTypeScriptSyntax(node) && !(currentNamespace && hasModifier(node, ModifierFlags.Export))) {
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
|
||||
const savedPendingExpressions = pendingExpressions;
|
||||
pendingExpressions = undefined;
|
||||
|
||||
|
@ -890,16 +883,11 @@ namespace ts {
|
|||
return statement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a class expression with TypeScript syntax into compatible ES6.
|
||||
*
|
||||
* This function will only be called when one of the following conditions are met:
|
||||
* - The class has property declarations with initializers.
|
||||
* - The class contains a constructor that contains parameters with accessibility modifiers.
|
||||
*
|
||||
* @param node The node to transform.
|
||||
*/
|
||||
function visitClassExpression(node: ClassExpression): Expression {
|
||||
if (!isClassLikeDeclarationWithTypeScriptSyntax(node)) {
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
|
||||
const savedPendingExpressions = pendingExpressions;
|
||||
pendingExpressions = undefined;
|
||||
|
||||
|
@ -2237,18 +2225,11 @@ namespace ts {
|
|||
* @param node The HeritageClause to transform.
|
||||
*/
|
||||
function visitHeritageClause(node: HeritageClause): HeritageClause | undefined {
|
||||
if (node.token === SyntaxKind.ExtendsKeyword) {
|
||||
const types = visitNodes(node.types, visitor, isExpressionWithTypeArguments, 0, 1);
|
||||
return setTextRange(
|
||||
createHeritageClause(
|
||||
SyntaxKind.ExtendsKeyword,
|
||||
types
|
||||
),
|
||||
node
|
||||
);
|
||||
if (node.token === SyntaxKind.ImplementsKeyword) {
|
||||
// implements clauses are elided
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2299,16 +2280,6 @@ namespace ts {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a method declaration of a class.
|
||||
*
|
||||
* This function will be called when one of the following conditions are met:
|
||||
* - The node is an overload
|
||||
* - The node is marked as abstract, public, private, protected, or readonly
|
||||
* - The node has a computed property name
|
||||
*
|
||||
* @param node The method node.
|
||||
*/
|
||||
function visitMethodDeclaration(node: MethodDeclaration) {
|
||||
if (!shouldEmitFunctionLikeDeclaration(node)) {
|
||||
return undefined;
|
||||
|
@ -2344,15 +2315,6 @@ namespace ts {
|
|||
return !(nodeIsMissing(node.body) && hasModifier(node, ModifierFlags.Abstract));
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a get accessor declaration of a class.
|
||||
*
|
||||
* This function will be called when one of the following conditions are met:
|
||||
* - The node is marked as abstract, public, private, or protected
|
||||
* - The node has a computed property name
|
||||
*
|
||||
* @param node The get accessor node.
|
||||
*/
|
||||
function visitGetAccessor(node: GetAccessorDeclaration) {
|
||||
if (!shouldEmitAccessorDeclaration(node)) {
|
||||
return undefined;
|
||||
|
@ -2375,15 +2337,6 @@ namespace ts {
|
|||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a set accessor declaration of a class.
|
||||
*
|
||||
* This function will be called when one of the following conditions are met:
|
||||
* - The node is marked as abstract, public, private, or protected
|
||||
* - The node has a computed property name
|
||||
*
|
||||
* @param node The set accessor node.
|
||||
*/
|
||||
function visitSetAccessor(node: SetAccessorDeclaration) {
|
||||
if (!shouldEmitAccessorDeclaration(node)) {
|
||||
return undefined;
|
||||
|
@ -2405,16 +2358,6 @@ namespace ts {
|
|||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a function declaration.
|
||||
*
|
||||
* This function will be called when one of the following conditions are met:
|
||||
* - The node is an overload
|
||||
* - The node is exported from a TypeScript namespace
|
||||
* - The node has decorators
|
||||
*
|
||||
* @param node The function node.
|
||||
*/
|
||||
function visitFunctionDeclaration(node: FunctionDeclaration): VisitResult<Statement> {
|
||||
if (!shouldEmitFunctionLikeDeclaration(node)) {
|
||||
return createNotEmittedStatement(node);
|
||||
|
@ -2438,14 +2381,6 @@ namespace ts {
|
|||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a function expression node.
|
||||
*
|
||||
* This function will be called when one of the following conditions are met:
|
||||
* - The node has type annotations
|
||||
*
|
||||
* @param node The function expression node.
|
||||
*/
|
||||
function visitFunctionExpression(node: FunctionExpression): Expression {
|
||||
if (!shouldEmitFunctionLikeDeclaration(node)) {
|
||||
return createOmittedExpression();
|
||||
|
@ -2463,11 +2398,6 @@ namespace ts {
|
|||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* This function will be called when one of the following conditions are met:
|
||||
* - The node has type annotations
|
||||
*/
|
||||
function visitArrowFunction(node: ArrowFunction) {
|
||||
const updated = updateArrowFunction(
|
||||
node,
|
||||
|
@ -2481,22 +2411,12 @@ namespace ts {
|
|||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a parameter declaration node.
|
||||
*
|
||||
* This function will be called when one of the following conditions are met:
|
||||
* - The node has an accessibility modifier.
|
||||
* - The node has a questionToken.
|
||||
* - The node's kind is ThisKeyword.
|
||||
*
|
||||
* @param node The parameter declaration node.
|
||||
*/
|
||||
function visitParameter(node: ParameterDeclaration) {
|
||||
if (parameterIsThisKeyword(node)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const parameter = createParameter(
|
||||
const updated = updateParameter(
|
||||
node,
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
node.dotDotDotToken,
|
||||
|
@ -2505,24 +2425,17 @@ namespace ts {
|
|||
/*type*/ undefined,
|
||||
visitNode(node.initializer, visitor, isExpression)
|
||||
);
|
||||
|
||||
// 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(parameter, node);
|
||||
setTextRange(parameter, moveRangePastModifiers(node));
|
||||
setCommentRange(parameter, node);
|
||||
setSourceMapRange(parameter, moveRangePastModifiers(node));
|
||||
setEmitFlags(parameter.name, EmitFlags.NoTrailingSourceMap);
|
||||
|
||||
return parameter;
|
||||
if (updated !== node) {
|
||||
// While we emit the source map for the node after skipping decorators and modifiers,
|
||||
// we need to emit the comments for the original range.
|
||||
setCommentRange(updated, node);
|
||||
setTextRange(updated, moveRangePastModifiers(node));
|
||||
setSourceMapRange(updated, moveRangePastModifiers(node));
|
||||
setEmitFlags(updated.name, EmitFlags.NoTrailingSourceMap);
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a variable statement in a namespace.
|
||||
*
|
||||
* This function will be called when one of the following conditions are met:
|
||||
* - The node is exported from a TypeScript namespace.
|
||||
*/
|
||||
function visitVariableStatement(node: VariableStatement): Statement | undefined {
|
||||
if (isExportOfNamespace(node)) {
|
||||
const variables = getInitializedVariables(node.declarationList);
|
||||
|
@ -2576,12 +2489,6 @@ namespace ts {
|
|||
visitNode(node.initializer, visitor, isExpression));
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a parenthesized expression that contains either a type assertion or an `as`
|
||||
* expression.
|
||||
*
|
||||
* @param node The parenthesized expression node.
|
||||
*/
|
||||
function visitParenthesizedExpression(node: ParenthesizedExpression): Expression {
|
||||
const innerExpression = skipOuterExpressions(node.expression, ~OuterExpressionKinds.Assertions);
|
||||
if (isAssertionExpression(innerExpression)) {
|
||||
|
|
|
@ -5041,37 +5041,34 @@ namespace ts {
|
|||
|
||||
// Facts
|
||||
// - Flags used to indicate that a node or subtree contains syntax that requires transformation.
|
||||
TypeScript = 1 << 0,
|
||||
ContainsTypeScript = 1 << 1,
|
||||
ContainsJsx = 1 << 2,
|
||||
ContainsESNext = 1 << 3,
|
||||
ContainsES2018 = 1 << 4,
|
||||
ContainsES2017 = 1 << 5,
|
||||
ContainsES2016 = 1 << 6,
|
||||
ContainsES2015 = 1 << 7,
|
||||
Generator = 1 << 8,
|
||||
ContainsGenerator = 1 << 9,
|
||||
DestructuringAssignment = 1 << 10,
|
||||
ContainsDestructuringAssignment = 1 << 11,
|
||||
ContainsTypeScript = 1 << 0,
|
||||
ContainsJsx = 1 << 1,
|
||||
ContainsESNext = 1 << 2,
|
||||
ContainsES2018 = 1 << 3,
|
||||
ContainsES2017 = 1 << 4,
|
||||
ContainsES2016 = 1 << 5,
|
||||
ContainsES2015 = 1 << 6,
|
||||
Generator = 1 << 7,
|
||||
ContainsGenerator = 1 << 8,
|
||||
DestructuringAssignment = 1 << 9,
|
||||
ContainsDestructuringAssignment = 1 << 10,
|
||||
|
||||
// Markers
|
||||
// - Flags used to indicate that a subtree contains a specific transformation.
|
||||
ContainsTypeScriptClassSyntax = 1 << 12, // Decorators, Property Initializers, Parameter Property Initializers
|
||||
|
||||
ContainsLexicalThis = 1 << 13,
|
||||
ContainsCapturedLexicalThis = 1 << 14,
|
||||
|
||||
ContainsLexicalThisInComputedPropertyName = 1 << 15,
|
||||
ContainsRestOrSpread = 1 << 16,
|
||||
ContainsObjectRestOrSpread = 1 << 17,
|
||||
ContainsComputedPropertyName = 1 << 18,
|
||||
ContainsBlockScopedBinding = 1 << 19,
|
||||
ContainsBindingPattern = 1 << 20,
|
||||
ContainsYield = 1 << 21,
|
||||
ContainsHoistedDeclarationOrCompletion = 1 << 22,
|
||||
ContainsDynamicImport = 1 << 23,
|
||||
Super = 1 << 24,
|
||||
ContainsSuper = 1 << 25,
|
||||
ContainsTypeScriptClassSyntax = 1 << 11, // Decorators, Property Initializers, Parameter Property Initializers
|
||||
ContainsLexicalThis = 1 << 12,
|
||||
ContainsCapturedLexicalThis = 1 << 13,
|
||||
ContainsLexicalThisInComputedPropertyName = 1 << 14,
|
||||
ContainsRestOrSpread = 1 << 15,
|
||||
ContainsObjectRestOrSpread = 1 << 16,
|
||||
ContainsComputedPropertyName = 1 << 17,
|
||||
ContainsBlockScopedBinding = 1 << 18,
|
||||
ContainsBindingPattern = 1 << 19,
|
||||
ContainsYield = 1 << 20,
|
||||
ContainsHoistedDeclarationOrCompletion = 1 << 21,
|
||||
ContainsDynamicImport = 1 << 22,
|
||||
Super = 1 << 23,
|
||||
ContainsSuper = 1 << 24,
|
||||
|
||||
// Please leave this as 1 << 29.
|
||||
// It is the maximum bit we can set before we outgrow the size of a v8 small integer (SMI) on an x86 system.
|
||||
|
@ -5080,7 +5077,7 @@ namespace ts {
|
|||
|
||||
// Assertions
|
||||
// - Bitmasks that are used to assert facts about the syntax of a node and its subtree.
|
||||
AssertTypeScript = TypeScript | ContainsTypeScript,
|
||||
AssertTypeScript = ContainsTypeScript,
|
||||
AssertJsx = ContainsJsx,
|
||||
AssertESNext = ContainsESNext,
|
||||
AssertES2018 = ContainsES2018,
|
||||
|
@ -5093,7 +5090,7 @@ namespace ts {
|
|||
// Scope Exclusions
|
||||
// - Bitmasks that exclude flags from propagating out of a specific context
|
||||
// into the subtree flags of their container.
|
||||
OuterExpressionExcludes = TypeScript | DestructuringAssignment | Generator | HasComputedFlags,
|
||||
OuterExpressionExcludes = DestructuringAssignment | Generator | HasComputedFlags,
|
||||
PropertyAccessExcludes = OuterExpressionExcludes | Super,
|
||||
NodeExcludes = PropertyAccessExcludes | ContainsSuper,
|
||||
ArrowFunctionExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread,
|
||||
|
|
|
@ -11,4 +11,4 @@ var d = () => ((<Error>({ name: "foo", message: "bar" })));
|
|||
var a = function () { return ({ name: "foo", message: "bar" }); };
|
||||
var b = function () { return ({ name: "foo", message: "bar" }); };
|
||||
var c = function () { return ({ name: "foo", message: "bar" }); };
|
||||
var d = function () { return (({ name: "foo", message: "bar" })); };
|
||||
var d = function () { return ({ name: "foo", message: "bar" }); };
|
||||
|
|
|
@ -11,4 +11,4 @@ var d = () => ((<Error>({ name: "foo", message: "bar" })));
|
|||
var a = () => ({ name: "foo", message: "bar" });
|
||||
var b = () => ({ name: "foo", message: "bar" });
|
||||
var c = () => ({ name: "foo", message: "bar" });
|
||||
var d = () => (({ name: "foo", message: "bar" }));
|
||||
var d = () => ({ name: "foo", message: "bar" });
|
||||
|
|
|
@ -17,9 +17,7 @@ let o = {
|
|||
string; // should be => not :
|
||||
// doesn't work in non-type contexts, where the return type is optional
|
||||
var f = function (n) { return function (string) { return n.toString(); }; };
|
||||
var o = {
|
||||
m: function (n) { }
|
||||
};
|
||||
var o = {};
|
||||
string;
|
||||
{
|
||||
return n.toString();
|
||||
|
|
|
@ -2,5 +2,4 @@
|
|||
function f(p: A) => p;
|
||||
|
||||
//// [parserErrantEqualsGreaterThanAfterFunction2.js]
|
||||
function f(p) { }
|
||||
p;
|
||||
|
|
|
@ -321,7 +321,6 @@ function modifiers() { return this.n; }
|
|||
function restParam(...) { return this.n; }
|
||||
function optional() { return this.n; }
|
||||
function decorated() { return this.n; }
|
||||
function initializer(, C) { }
|
||||
();
|
||||
number;
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue