-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Add wrapper to emit statics/decorators inside es5 class #16120
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
Changes from 1 commit
b8ee169
b69afd1
423d8a0
636cd7c
6159206
d876fcc
3ddbfca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2130,6 +2130,24 @@ namespace ts { | |
|
||
// Compound nodes | ||
|
||
export function createImmediatelyInvokedFunctionExpression(statements: Statement[]): CallExpression; | ||
export function createImmediatelyInvokedFunctionExpression(statements: Statement[], param: ParameterDeclaration, paramValue: Expression): CallExpression; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, these are not arrays. As written, this function only allows zero or one parameter. |
||
export function createImmediatelyInvokedFunctionExpression(statements: Statement[], param?: ParameterDeclaration, paramValue?: Expression) { | ||
return createCall( | ||
createFunctionExpression( | ||
/*modifiers*/ undefined, | ||
/*asteriskToken*/ undefined, | ||
/*name*/ undefined, | ||
/*typeParameters*/ undefined, | ||
/*parameters*/ param ? [param] : [], | ||
/*type*/ undefined, | ||
createBlock(statements, /*multiLine*/ true) | ||
), | ||
/*typeArguments*/ undefined, | ||
/*argumentsArray*/ paramValue ? [paramValue] : [] | ||
); | ||
} | ||
|
||
export function createComma(left: Expression, right: Expression) { | ||
return <Expression>createBinary(left, SyntaxKind.CommaToken, right); | ||
} | ||
|
@@ -3212,6 +3230,26 @@ namespace ts { | |
return isBlock(node) ? node : setTextRange(createBlock([setTextRange(createReturn(node), node)], multiLine), node); | ||
} | ||
|
||
export function convertFunctionDeclarationToExpression(node: FunctionDeclaration) { | ||
Debug.assert(!!node.body); | ||
const updated = createFunctionExpression( | ||
node.modifiers, | ||
node.asteriskToken, | ||
node.name, | ||
node.typeParameters, | ||
node.parameters, | ||
node.type, | ||
node.body | ||
); | ||
setOriginalNode(updated, node); | ||
setTextRange(updated, node); | ||
if (node.startsOnNewLine) { | ||
updated.startsOnNewLine = true; | ||
} | ||
aggregateTransformFlags(updated); | ||
return updated; | ||
} | ||
|
||
function isUseStrictPrologue(node: ExpressionStatement): boolean { | ||
return (node.expression as StringLiteral).text === "use strict"; | ||
} | ||
|
@@ -3610,7 +3648,7 @@ namespace ts { | |
if (kind === SyntaxKind.FunctionExpression || kind === SyntaxKind.ArrowFunction) { | ||
const mutableCall = getMutableClone(emittedExpression); | ||
mutableCall.expression = setTextRange(createParen(callee), callee); | ||
return recreatePartiallyEmittedExpressions(expression, mutableCall); | ||
return recreateOuterExpressions(expression, mutableCall, OuterExpressionKinds.PartiallyEmittedExpressions); | ||
} | ||
} | ||
else { | ||
|
@@ -3652,22 +3690,6 @@ namespace ts { | |
} | ||
} | ||
|
||
/** | ||
* Clones a series of not-emitted expressions with a new inner expression. | ||
* | ||
* @param originalOuterExpression The original outer expression. | ||
* @param newInnerExpression The new inner expression. | ||
*/ | ||
function recreatePartiallyEmittedExpressions(originalOuterExpression: Expression, newInnerExpression: Expression) { | ||
if (isPartiallyEmittedExpression(originalOuterExpression)) { | ||
const clone = getMutableClone(originalOuterExpression); | ||
clone.expression = recreatePartiallyEmittedExpressions(clone.expression, newInnerExpression); | ||
return clone; | ||
} | ||
|
||
return newInnerExpression; | ||
} | ||
|
||
function getLeftmostExpression(node: Expression): Expression { | ||
while (true) { | ||
switch (node.kind) { | ||
|
@@ -3714,6 +3736,21 @@ namespace ts { | |
All = Parentheses | Assertions | PartiallyEmittedExpressions | ||
} | ||
|
||
export type OuterExpression = ParenthesizedExpression | TypeAssertion | AsExpression | PartiallyEmittedExpression; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It didn't exist when |
||
|
||
export function isOuterExpression(node: Node, kinds = OuterExpressionKinds.All): node is OuterExpression { | ||
switch (node.kind) { | ||
case SyntaxKind.ParenthesizedExpression: | ||
return (kinds & OuterExpressionKinds.Parentheses) !== 0; | ||
case SyntaxKind.TypeAssertionExpression: | ||
case SyntaxKind.AsExpression: | ||
return (kinds & OuterExpressionKinds.Assertions) !== 0; | ||
case SyntaxKind.PartiallyEmittedExpression: | ||
return (kinds & OuterExpressionKinds.PartiallyEmittedExpressions) !== 0; | ||
} | ||
return false; | ||
} | ||
|
||
export function skipOuterExpressions(node: Expression, kinds?: OuterExpressionKinds): Expression; | ||
export function skipOuterExpressions(node: Node, kinds?: OuterExpressionKinds): Node; | ||
export function skipOuterExpressions(node: Node, kinds = OuterExpressionKinds.All) { | ||
|
@@ -3767,6 +3804,25 @@ namespace ts { | |
return node; | ||
} | ||
|
||
function updateOuterExpression(outerExpression: OuterExpression, expression: Expression) { | ||
switch (outerExpression.kind) { | ||
case SyntaxKind.ParenthesizedExpression: return updateParen(outerExpression, expression); | ||
case SyntaxKind.TypeAssertionExpression: return updateTypeAssertion(outerExpression, outerExpression.type, expression); | ||
case SyntaxKind.AsExpression: return updateAsExpression(outerExpression, expression, outerExpression.type); | ||
case SyntaxKind.PartiallyEmittedExpression: return updatePartiallyEmittedExpression(outerExpression, expression); | ||
} | ||
} | ||
|
||
export function recreateOuterExpressions(outerExpression: Expression | undefined, innerExpression: Expression, kinds = OuterExpressionKinds.All): Expression { | ||
if (outerExpression && isOuterExpression(outerExpression, kinds)) { | ||
return updateOuterExpression( | ||
outerExpression, | ||
recreateOuterExpressions(outerExpression.expression, innerExpression) | ||
); | ||
} | ||
return innerExpression; | ||
} | ||
|
||
export function startOnNewLine<T extends Node>(node: T): T { | ||
node.startsOnNewLine = true; | ||
return node; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't see any reason to allow an
undefined
parameter since the function will always fail in that case.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we ever turn on
--strictNullChecks
there may be cases wherevalue
may be typedundefined
.