Skip to content
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

Enable the noImplicitThis tsc option #14545

Merged
merged 3 commits into from May 22, 2022

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented May 11, 2022

Q                       A
License MIT

In this PR we enable the noImplicitThis compiler option and fixes all the new typing errors.

This PR is based on #14530, whose changes implicitly fix noImplicitThis errors.

@babel-bot
Copy link
Collaborator

babel-bot commented May 11, 2022

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/51973/

@JLHwung JLHwung changed the title Enable noImplicitThis tsc options Enable the noImplicitThis tsc option May 11, 2022
@@ -127,7 +129,7 @@ export default declare((api, options: Options) => {
AssignmentExpression(path) {
const left = path.get("left");
if (left.isIdentifier()) {
const localName = path.node.name;
const localName = left.node.name;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug fix. Babel does not replace module in module = {} to assertion errors because path.node.name is always undefined.

throw new Error("The CommonJS '" + "exports" + "' variable is not available in ES6 modules." + "Consider setting setting sourceType:script or sourceType:unambiguous in your " + "Babel config for this file.");
}() + 4, function () {
throw new Error("The CommonJS '" + "exports" + "' variable is not available in ES6 modules." + "Consider setting setting sourceType:script or sourceType:unambiguous in your " + "Babel config for this file.");
}());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can avoid emitting the error twice. I think it's duplicated because exports += 4 is handled like exports = exports + 4, so we emit one error for the read and one for the write.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super low priority: since the generated code always throw, it's will almost never be included in production code.

@JLHwung JLHwung force-pushed the enable-no-implicit-this branch 2 times, most recently from ed94e39 to efc934e Compare May 17, 2022 17:58
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I highlighted below the code differences (everything else are only type changes).

Comment on lines +110 to 112
if (!arg.isIdentifier()) return;
const localName = arg.node.name;
if (localName !== "module" && localName !== "exports") return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code change doesn't have any effect on the result, other than making the code "sound". If arg is not an identifier, arg.node.name is undefined and thus we returned.


let type = this._getTypeAnnotation() || anyTypeAnnotation();
export function getTypeAnnotation(this: NodePath): t.FlowType {
let type = this.getData("typeAnnotation");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this code change we use the internal map storage that NodePath supports, rather than just adding an extra property on the path object.

@nicolo-ribaudo nicolo-ribaudo merged commit 8f904e0 into babel:main May 22, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the enable-no-implicit-this branch May 22, 2022 11:07
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Aug 22, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants