Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed
mhegazy opened this issue Aug 26, 2014 · 7 comments · Fixed by #624
Closed

[spec] Grammar does not allow ambients inside an internal module #533

mhegazy opened this issue Aug 26, 2014 · 7 comments · Fixed by #624
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Spec Issues related to the TypeScript language specification

Comments

@mhegazy
Copy link
Contributor

mhegazy commented Aug 26, 2014

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.

@sophiajt sophiajt added this to the TypeScript 1.2 milestone Aug 26, 2014
@mhegazy mhegazy modified the milestones: TypeScript 1.2, TypeScript 1.1 Aug 29, 2014
@ahejlsberg
Copy link
Member

This is by design. Ambient declarations are only allowed at the top level (see sections 11.1 and 12.1 in the spec).

@JsonFreeman
Copy link
Contributor

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.

@JsonFreeman JsonFreeman reopened this Sep 2, 2014
@RyanCavanaugh
Copy link
Member

e.g.
https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Physics/babylon.physicsEngine.ts
https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Physics/Plugins/babylon.cannonJSPlugin.ts

It's also very useful when you want to directly use node.js's require without having to pollute the global scope with it (this is a very real problem when using node.d.ts with any of the compiler .d.ts files at the same time, for example).

@ahejlsberg
Copy link
Member

Ok, got it. Will fix the spec.

@JsonFreeman
Copy link
Contributor

This was updated in section 10.2, but still needs to be updated in the Grammar appendix.

@JsonFreeman JsonFreeman reopened this Sep 6, 2014
@JsonFreeman
Copy link
Contributor

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.

@ahejlsberg
Copy link
Member

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.

@RyanCavanaugh RyanCavanaugh added the Fixed A PR has been merged for this issue label Sep 8, 2014
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Spec Issues related to the TypeScript language specification
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants