-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly visit param decorators to prevent their imports being remov…
…ed in typescript transform (#8738) * Remove types on program exit in typescript transform * Revert changes to typescript transform * Correctly add visitors for param decorators * Fix plugin for node 6
- Loading branch information
1 parent
46ba594
commit 854313a
Showing
6 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
...es/babel-plugin-transform-typescript/test/fixtures/imports/parameter-decorators/input.mjs
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { NgModule, Optional, SkipSelf } from '@angular/core'; | ||
|
||
@NgModule({}) | ||
export class CoreModule { | ||
constructor(@Optional() @SkipSelf() parentModule) { } | ||
} |
12 changes: 12 additions & 0 deletions
12
...babel-plugin-transform-typescript/test/fixtures/imports/parameter-decorators/options.json
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"plugins": [ | ||
"transform-typescript", | ||
[ | ||
"proposal-decorators", | ||
{ | ||
"legacy": true | ||
} | ||
], | ||
"./plugin" | ||
] | ||
} |
9 changes: 9 additions & 0 deletions
9
...s/babel-plugin-transform-typescript/test/fixtures/imports/parameter-decorators/output.mjs
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var _dec, _class; | ||
|
||
import { NgModule, Optional, SkipSelf } from '@angular/core'; | ||
export let CoreModule = (_dec = NgModule({}), _dec(_class = class CoreModule { | ||
constructor(_parentModule) { | ||
var _parentModule2 = Optional()(SkipSelf()(_parentModule)); | ||
} | ||
|
||
}) || _class); |
54 changes: 54 additions & 0 deletions
54
...es/babel-plugin-transform-typescript/test/fixtures/imports/parameter-decorators/plugin.js
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"use strict"; | ||
// https://github.com/benderTheCrime/babel-plugin-transform-function-parameter-decorators/ | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true, | ||
}); | ||
|
||
exports.default = function(_ref) { | ||
var types = _ref.types; | ||
|
||
return { | ||
visitor: { | ||
Function: function parseFunctionPath(path) { | ||
(path.get("params") || []) | ||
.slice() | ||
.reverse() | ||
.forEach(function(param) { | ||
var name = param.node.name; | ||
var paramUidName = path.scope.generateUidIdentifier(name).name; | ||
var resultantDecorator = void 0; | ||
|
||
(param.node.decorators || []) | ||
.slice() | ||
.reverse() | ||
.forEach(function(decorator) { | ||
resultantDecorator = types.callExpression( | ||
decorator.expression, | ||
[resultantDecorator || types.Identifier(paramUidName)] | ||
); | ||
}); | ||
|
||
if (resultantDecorator) { | ||
var decoratedParamUidName = path.scope.generateUidIdentifier(name) | ||
.name; | ||
|
||
path.scope.rename(name, decoratedParamUidName); | ||
param.parentPath | ||
.get("body") | ||
.unshiftContainer( | ||
"body", | ||
types.variableDeclaration("var", [ | ||
types.variableDeclarator( | ||
types.Identifier(decoratedParamUidName), | ||
resultantDecorator | ||
), | ||
]) | ||
); | ||
param.replaceWith(types.Identifier(paramUidName)); | ||
} | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
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