initial revision of external module augmentations#6213
Conversation
src/compiler/binder.ts
Outdated
There was a problem hiding this comment.
I don't see this getting used anywhere apart from the later assignment.
There was a problem hiding this comment.
right, forgot to remove that. Thanks
src/compiler/checker.ts
Outdated
There was a problem hiding this comment.
isGlobalAugmentation or augmentsGlobal
|
What exactly is the recommended way to augment a default export? Is it possible in this implementation? |
|
it is not possible |
|
This also appears to take care of #2784. You might want to take note and give a heads up on that issue when this goes in. |
There was a problem hiding this comment.
what about external modules with no exports or no module augmentation? soemthing like:
import {a} from "./mod";
// do something with aThere was a problem hiding this comment.
i thought we will do this for any external module, that we never emitted any import, export, or module augmentation for.
|
👍 |
src/compiler/checker.ts
Outdated
There was a problem hiding this comment.
This should be checkModuleAugmentationElement. It checks and element in the body, not the body itself.
|
build failure is related to #6478 |
|
@ahejlsberg done, do you have any other comments? |
There was a problem hiding this comment.
The error message below seems a bit odd for this case, but maybe it's fine.
There was a problem hiding this comment.
for global case we can easily lift this restriction since it is possible to add new entries to global scope from within a module. Currently the fact that we have it is only because of consistency in behavior for augmentations.
There was a problem hiding this comment.
No sure I understand, maybe we're talking about different issues. This code is saying that you get an error when you have an exported member in a global augmentation block, right? I'm thinking it should never be valid to use export in a global augmentation block.
There was a problem hiding this comment.
the idea of this check is following: symbol.parent will be undefined if symbol was initially defined in the global scope. If symbol.parent is not undefined this means that this symbol was declared inside augmentation and will declare new entry in the global scope which is disallowed in current design
There was a problem hiding this comment.
If symbol.parent is not undefined this means that this symbol was declared inside augmentation
Why is that so? symbol.parent is non-undefined when the symbol is exported, but it might still be declared inside the augmentation. I'm not getting this.
There was a problem hiding this comment.
symbols whose initial declaration is in global scope are never exported and symbol.parent for them is always undefined. if symbol.parent !== undefined this means that this symbol is exported from somewhere and as a consequence initially defined in augmentation not in global scope
|
In |
src/compiler/checker.ts
Outdated
There was a problem hiding this comment.
I have a hard time reasoning about this.
There was a problem hiding this comment.
this assert is redundant. it basically says: augmentation can only change exported symbol (parent !== undefeind) that really has a declaration (not a virtual symbol like prototype) - this should always be the case. I'll remove it
There was a problem hiding this comment.
So did you mean symbol.valueDeclaration !== undefined? You currently have symbol.parent.valueDeclaration.
There was a problem hiding this comment.
symbol.parent.valueDeclaration - is an augmentation: declare module .... symbol.valueDeclaration is declaration inside the augmentation. Currently we report error if container that this symbol is module augmentation and not a normal external module
initial revision of external module augmentations
|
Awesome! Great stuff. Thank you! |
|
🎉 👏 👏 👏 👏 👏 👏 👏 |
|
👍 |
Module augmentation is a declaration of ambient module that directly nested either in external module or in top level ambient external module.
Name of module augmentation is resolved using the same set of rules as module specifiers in import \ export declarations.
If name is successfully resolved to some external module then declarations in module augmentation are merged with declarations inside module using standard rules for declaration merging.
Module augmentations cannot add new items to the top level scope but rather patch existing declarations.
for example
Here module
mapcan declare that internally it will patchObservabletype and addmapfunction to it.Fixes: #5269, #6022
Pending work:
"/"but this is just a placeholder. The version that we ended up during the design meeting was:or