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

Don’t create expando declarations on alias symbols #39558

Merged
merged 4 commits into from
Jul 13, 2020

Conversation

andrewbranch
Copy link
Member

@andrewbranch andrewbranch commented Jul 10, 2020

Fixes #38218

This is also the antifix of #26912 🤷‍♂️. #32626 didn’t actually solve #26912; it just stopped reporting errors on it. #38218 shows that when an expando merges with an alias in JS, the alias target is actually unreachable. It looks like going in the other direction and making expandos on aliases actually work would be a bit more effort. I’m not sure anyone is asking for that anyway.

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

I think it's OK as-is, but it be even better if the iteration in the binder early-exited.

src/compiler/binder.ts Outdated Show resolved Hide resolved
@sandersn
Copy link
Member

Also maybe other callers of forEachIdentifierInEntityName should not work on aliases either.

sandersn added a commit that referenced this pull request Jul 10, 2020
taken from #39558 as soon as it was created
@andrewbranch
Copy link
Member Author

You’re right; the check can actually be moved to the top of bindPotentiallyMissingNamespaces. I wasn’t thinking about the fact that the nested namespaces in the entity name can’t possibly be alias symbols.

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

From other discussion, I figured out that other callers of forEachIdentifierInEntityName never operate on aliases.

@andrewbranch andrewbranch merged commit 583bd92 into microsoft:master Jul 13, 2020
@andrewbranch andrewbranch deleted the bug/38218 branch July 13, 2020 17:05
sandersn added a commit that referenced this pull request Aug 17, 2020
* First attempt at aliases for require

* test+initial support for const x=require

* 1st round of baseline improvements

* 2nd round of baseline updates

* support property access after require

* check @type tag on require

* forbid expando missing namespaces on aliases

taken from #39558 as soon as it was created

* accept error baselines that are good, actually

* Scribbling on d.ts emit code

* use getSpecifierForModuleSymbol

* hideous hack for module.exports of aliases

* Fix module.exports.x --> export list emit

* fix isLocalImport predicate

* require only creates aliases in JS

* re-handle json imports

* update fourslash baseline

* Cleanup in the checker

1. Simplify alias resolution.
2. Simplify variable-like checking.
3. Make binding skip require calls with type tags -- they fall back to
the old require-call code and then check from there.

I haven't started on the declaration emit code since I don't know what
is going on there nearly as well.

* Function for getting module name from require call

* First round of cleanup plus a new test

Found one missing feature, not sure it's worth adding.

* more small cleanup

* more cleanup, including lint

* use trackSymbol, not serializeTypeForDeclaration

* Code review comments, plus remove unneeded code

Ad-hoc type reference resolution for `require` isn't needed anymore.

* find all refs works

* remove old ad-hoc code

* make it clear that old behaviour is not that correct

* update api baselines

* remove outdated comment

* PR feedback

1. Fix indentation
2. Add comment for exported JSON emit
3. Add test case for nested-namespace exports.

* add a fail-case test (which passes!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding property to 'import Vue from 'vue'' import makes 'Vue' no longer constructible
3 participants