Introduce scope tracking in the parser (#9493)
* Introduce scope tracking * Fix tests * Add new tests * Remove constructor-super check from transform as it is now in parser * Correctly handle class properties and class scope * Fix duplicate name check * Convert scope identifier storage to array * Enter a new scope in typescript module blocks * Add test for duplicate declaration * Rename error for duplicate exports * Treat class declarations as lexical declaration * Update whitelist * Add tests * Fix scope tracking for function declarations * Migrate try-catch duplicate error * Fix test * More tests * One more test * Make scope a separate class and fix review comments * Do not allow new.target in top scope arrow function * Correctly enter new scope for declare module and treat type aliases as lexical declarations * Tests for typescript scope tracking to not mark type aliases as duplicate * Fix flow scope tracking * Remove ident from test names as redundant * Add test case for var and function * Improve error messages * Improve literal regex
This commit is contained in:
@@ -19,22 +19,6 @@ function buildConstructor(classRef, constructorBody, node) {
|
||||
return func;
|
||||
}
|
||||
|
||||
const verifyConstructorVisitor = traverse.visitors.merge([
|
||||
environmentVisitor,
|
||||
{
|
||||
Super(path, state) {
|
||||
if (state.isDerived) return;
|
||||
|
||||
const { node, parentPath } = path;
|
||||
if (parentPath.isCallExpression({ callee: node })) {
|
||||
throw path.buildCodeFrameError(
|
||||
"super() is only allowed in a derived constructor",
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
export default function transformClass(
|
||||
path: NodePath,
|
||||
file: any,
|
||||
@@ -180,13 +164,6 @@ export default function transformClass(
|
||||
if (t.isClassMethod(node)) {
|
||||
const isConstructor = node.kind === "constructor";
|
||||
|
||||
if (isConstructor) {
|
||||
path.traverse(verifyConstructorVisitor, {
|
||||
isDerived: classState.isDerived,
|
||||
file: classState.file,
|
||||
});
|
||||
}
|
||||
|
||||
const replaceSupers = new ReplaceSupers({
|
||||
methodPath: path,
|
||||
objectRef: classState.classRef,
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
class Foo {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"throws": "super() is only allowed in a derived constructor",
|
||||
"plugins": ["transform-classes"]
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"throws": "super() is only valid inside a class constructor. Make sure the method name is spelled exactly as 'constructor'."
|
||||
"throws": "super() is only valid inside a class constructor of a subclass. Maybe a typo in the method name ('constructor') or not extending another class?"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user