Skip to content

Adds the Module transformers #7206

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

Merged
merged 17 commits into from
Mar 18, 2016

Conversation

rbuckton
Copy link
Contributor

The Module transformer is designed to transform most Module-specific syntax into compatible down-level JavaScript, including:

  • Top-level Import Declarations
  • Top-level Export Declarations
  • Default exports and export assignments
  • Exported functions and classes

The Module transformers include support for the following module kinds:

  • CommonJS
  • AMD
  • UMD
  • SystemJS
  • ES6 (which is effectively a no-op).

Related Pull Requests:

define,
flattenNodes([
// Add the module name (if provided).
moduleName,
Copy link
Member

Choose a reason for hiding this comment

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

If it's undefined, will it be skipped in the emit or emitted as undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

flattenNodes removes undefined nodes.

const moduleName = getExternalModuleNameLiteral(importNode);
return createCall(
createIdentifier("require"),
moduleName ? [moduleName] : []
Copy link
Member

Choose a reason for hiding this comment

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

without moduleName, this just generates require(), right? What will the larger generated statement be in that case, and is it meaningful?


function visitExportDeclaration(node: ExportDeclaration): OneOrMany<Statement> {
if (contains(externalImports, node)) {
const generatedName = getGeneratedNameForNode(node);
Copy link
Member

Choose a reason for hiding this comment

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

why does visitExportDeclaration save the result of getGeneratedNameForNode but visitImportDeclaration and visitImportEqualsDeclaration doesn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • visitExportDeclaration must always call getGeneratedNameForNode.
  • visitImportDeclaration calls it conditionally.
  • visitImportEqualsDeclaration doesn't call it at all.

rbuckton added a commit that referenced this pull request Mar 18, 2016
@rbuckton rbuckton merged commit 3c5f170 into transforms-transformer-es6 Mar 18, 2016
@rbuckton rbuckton deleted the transforms-transformer-module branch March 18, 2016 21:37
@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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants