Skip to content

Conversation

sandersn
Copy link
Member

Fixes #7874

ES6 imports and exports are illegal inside namespaces. In order to emit syntactically legal code, skip emit for these incorrect statements.

Fixes tests:

  1. es5ModuleInternalNamedImport
  2. es6ModuleInternalNamedImports
  3. es6ModuleInternalNamedImports2
  4. exportDeclarationInInternalModule
  5. importInsideModule
  6. multipleExports
  7. privacyGloImportParseErrors
  8. privacyImportParseErrors*
  9. privacyCheckOnImportedModuleDeclarationsInsideModule

*Still has some incorrect, unrelated emit at the end of the module

ES6 imports and exports are illegal inside namespaces. In order to emit syntactically legal code, skip emit for these incorrect statements.
@sandersn sandersn changed the title Do not emit ES6 import/export inside namespaces [Transforms] Do not emit ES6 import/export inside namespaces Apr 12, 2016
@sandersn sandersn added the Domain: Transforms Relates to the public transform API label Apr 12, 2016
(node.kind === SyntaxKind.ImportEqualsDeclaration &&
(<ImportEqualsDeclaration>node).moduleReference.kind === SyntaxKind.ExternalModuleReference)) {
// do not emit ES6 imports and exports since they are illegal inside a namespace
return createNotEmittedStatement(node);
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious, why createNotEmittedStatements instead of just return undefined? Do we really need to preserve comments for illegally placed nodes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, I was trying to minimise the number of differences with the old emit, but createNotEmittedStatement didn't seem to work. I can definitely go back to return undefined.

@rbuckton
Copy link
Contributor

Assuming you address @vladima's comment above, 👍

@sandersn sandersn merged commit 34ad57a into transforms Apr 13, 2016
@sandersn sandersn deleted the transforms-skip-es6-imports-inside-namespace branch April 13, 2016 22:51
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Domain: Transforms Relates to the public transform API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants