-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add wrapper to emit statics/decorators inside es5 class #16120
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b8ee169
Add wrapper to emit statics/decorators inside es5 class
rbuckton b69afd1
PR Feedback
rbuckton 423d8a0
PR feedback
rbuckton 636cd7c
Merge branch 'master' into fix15857
rbuckton 6159206
Merge branch 'master' into fix15857
rbuckton d876fcc
Merge branch 'fix15857' of https://github.com/Microsoft/TypeScript in…
rbuckton 3ddbfca
Merge branch 'master' into fix15857
rbuckton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2134,6 +2134,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); | ||
} | ||
|
@@ -3216,6 +3234,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"; | ||
} | ||
|
@@ -3614,7 +3652,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 { | ||
|
@@ -3656,22 +3694,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) { | ||
|
@@ -3718,6 +3740,22 @@ namespace ts { | |
All = Parentheses | Assertions | PartiallyEmittedExpressions | ||
} | ||
|
||
export type OuterExpression = ParenthesizedExpression | TypeAssertion | AsExpression | NonNullExpression | PartiallyEmittedExpression; | ||
|
||
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: | ||
case SyntaxKind.NonNullExpression: | ||
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) { | ||
|
@@ -3754,8 +3792,8 @@ namespace ts { | |
export function skipAssertions(node: Expression): Expression; | ||
export function skipAssertions(node: Node): Node; | ||
export function skipAssertions(node: Node): Node { | ||
while (isAssertionExpression(node)) { | ||
node = (<AssertionExpression>node).expression; | ||
while (isAssertionExpression(node) || node.kind === SyntaxKind.NonNullExpression) { | ||
node = (<AssertionExpression | NonNullExpression>node).expression; | ||
} | ||
|
||
return node; | ||
|
@@ -3771,6 +3809,26 @@ 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.NonNullExpression: return updateNonNullExpression(outerExpression, expression); | ||
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.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
.