add legacy decorators support to strict class fields (#10616)
This PR allows legacy decorators to work with strict class fields, which are now stage 3 and have shipped in a number of browsers. Allowing this will allow users of the legacy transform (which is currently recommended by the champions of the decorator proposal) to use the proper class field semantics for non-decorated fields, which should help prevent breakage later on. This change is not a breaking change, since users had to explicitly opt into loose mode in class fields before. This just gives them the option to remove that opt-in.
This commit is contained in:
committed by
Huáng Jùnliàng
parent
bea1b0d0af
commit
5c0d8a9de7
@@ -290,4 +290,24 @@ export default {
|
||||
]),
|
||||
);
|
||||
},
|
||||
|
||||
CallExpression(path, state) {
|
||||
if (path.node.arguments.length !== 3) return;
|
||||
if (!WARNING_CALLS.has(path.node.arguments[2])) return;
|
||||
|
||||
// If the class properties plugin isn't enabled, this line will add an unused helper
|
||||
// to the code. It's not ideal, but it's ok since the configuration is not valid anyway.
|
||||
if (path.node.callee.name !== state.addHelper("defineProperty").name) {
|
||||
return;
|
||||
}
|
||||
|
||||
path.replaceWith(
|
||||
t.callExpression(state.addHelper("initializerDefineProperty"), [
|
||||
t.cloneNode(path.get("arguments")[0].node),
|
||||
t.cloneNode(path.get("arguments")[1].node),
|
||||
t.cloneNode(path.get("arguments.2.arguments")[0].node),
|
||||
t.cloneNode(path.get("arguments.2.arguments")[1].node),
|
||||
]),
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user