-
Notifications
You must be signed in to change notification settings - Fork 12.8k
[spec] Grammar does not allow ambients inside an internal module #533
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
Comments
This is by design. Ambient declarations are only allowed at the top level (see sections 11.1 and 12.1 in the spec). |
But ambient declarations inside nonambient modules is allowed by both compilers, and we have been supporting it. According to @RyanCavanaugh and @danquirk there are real world customers who depend on this. |
e.g. It's also very useful when you want to directly use node.js's |
Ok, got it. Will fix the spec. |
This was updated in section 10.2, but still needs to be updated in the Grammar appendix. |
Also, something else. The grammar was changed to remove AmbientExternalModuleDeclaration from AmbientDeclaration. However, the forbidding of nested ambient external modules appears to be in the semantic phase. So technically, the grammar should allow it by including AmbientExternalModuleDeclaration in AmbientDeclaration. |
I'd prefer to keep AmbientExternalModuleDeclaration out of AmbientDeclaration so that the grammar reflects the restriction. The fact that the compiler verifies it in the semantic phase is really just an implementation detail. |
Courtesy of @JsonFreeman
This is just an oversight in the grammar, but the ModuleElement production does not go to AmbientDeclaration on the right side, which implies that an internal module cannot contain ambients. It needs to be added to the RHS.
Actually you need to add AmbientDeclaration, but not including AmbientExternalModuleDeclaration.
The text was updated successfully, but these errors were encountered: