Skip to content
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

Expose syntheticNamedExports to ModuleInfo #3847

Merged
merged 6 commits into from Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/05-plugin-development.md
Expand Up @@ -647,6 +647,8 @@ Returns additional information about the module in question in the form
implicitlyLoadedAfterOneOf: string[], // implicit relationships, declared via this.emitChunk
implicitlyLoadedBefore: string[], // implicit relationships, declared via this.emitChunk
hasModuleSideEffects: boolean | "no-treeshake" // are imports of this module included if nothing is imported from it
meta: {[plugin: string]: any} // custom module meta-data
syntheticNamedExports: boolean | string // final value of synthetic named exports
}
```

Expand Down
3 changes: 2 additions & 1 deletion src/ExternalModule.ts
Expand Up @@ -58,7 +58,8 @@ export default class ExternalModule {
},
isEntry: false,
isExternal: true,
meta
meta,
syntheticNamedExports: false
Amareis marked this conversation as resolved.
Show resolved Hide resolved
};
}

Expand Down
6 changes: 5 additions & 1 deletion src/Module.ts
Expand Up @@ -284,7 +284,11 @@ export default class Module {
},
isEntry,
isExternal: false,
meta
meta,
get syntheticNamedExports() {
//since it's public and not readonly, we should use getter to ensure value is always actual
return module.syntheticNamedExports;
Amareis marked this conversation as resolved.
Show resolved Hide resolved
}
};
}

Expand Down
1 change: 1 addition & 0 deletions src/rollup/types.d.ts
Expand Up @@ -171,6 +171,7 @@ interface ModuleInfo {
isEntry: boolean;
isExternal: boolean;
meta: CustomPluginOptions;
syntheticNamedExports: boolean | string;
}

export type GetModuleInfo = (moduleId: string) => ModuleInfo | null;
Expand Down
Expand Up @@ -80,7 +80,8 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
});
assert.deepStrictEqual(JSON.parse(JSON.stringify(this.getModuleInfo(ID_DEP))), {
ast: {
Expand Down Expand Up @@ -138,7 +139,8 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
});
},
generateBundle(options, bundle) {
Expand Down
Expand Up @@ -76,7 +76,8 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
});
assert.deepStrictEqual(JSON.parse(JSON.stringify(this.getModuleInfo(ID_DEP))), {
ast: {
Expand Down Expand Up @@ -134,7 +135,8 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
});
},
generateBundle(options, bundle) {
Expand Down
Expand Up @@ -125,7 +125,8 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
});
assert.deepStrictEqual(JSON.parse(JSON.stringify(this.getModuleInfo(ID_MAIN2))), {
ast: {
Expand Down Expand Up @@ -219,7 +220,8 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
});
assert.deepStrictEqual(JSON.parse(JSON.stringify(this.getModuleInfo(ID_DEP))), {
ast: {
Expand Down Expand Up @@ -312,7 +314,8 @@ module.exports = {
importers: [],
isEntry: false,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
});
}
}
Expand Down
Expand Up @@ -75,7 +75,8 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
});
assert.deepStrictEqual(JSON.parse(JSON.stringify(this.getModuleInfo(ID_DEP))), {
ast: {
Expand Down Expand Up @@ -133,7 +134,8 @@ module.exports = {
importers: [],
isEntry: false,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
});
},
generateBundle(options, bundle) {
Expand Down
12 changes: 8 additions & 4 deletions test/function/samples/deprecated/manual-chunks-info/_config.js
Expand Up @@ -111,7 +111,8 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
},
{
ast: null,
Expand All @@ -126,7 +127,8 @@ module.exports = {
importers: [getId('main')],
isEntry: false,
isExternal: true,
meta: {}
meta: {},
syntheticNamedExports: false
},
{
ast: {
Expand Down Expand Up @@ -154,7 +156,8 @@ module.exports = {
importers: [getId('dynamic'), getId('main')],
isEntry: false,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
},
{
ast: {
Expand Down Expand Up @@ -226,7 +229,8 @@ module.exports = {
importers: [],
isEntry: false,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
}
]
);
Expand Down
12 changes: 8 additions & 4 deletions test/function/samples/manual-chunks-info/_config.js
Expand Up @@ -110,7 +110,8 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
},
{
ast: null,
Expand All @@ -125,7 +126,8 @@ module.exports = {
importers: [getId('main')],
isEntry: false,
isExternal: true,
meta: {}
meta: {},
syntheticNamedExports: false
},
{
ast: {
Expand Down Expand Up @@ -153,7 +155,8 @@ module.exports = {
importers: [getId('dynamic'), getId('main')],
isEntry: false,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
},
{
ast: {
Expand Down Expand Up @@ -225,7 +228,8 @@ module.exports = {
importers: [],
isEntry: false,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
}
]
);
Expand Down
6 changes: 4 additions & 2 deletions test/function/samples/module-parsed-hook/_config.js
Expand Up @@ -58,7 +58,8 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
},
{
ast: {
Expand Down Expand Up @@ -102,7 +103,8 @@ module.exports = {
importers: [ID_MAIN],
isEntry: false,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
}
]);
}
Expand Down
15 changes: 10 additions & 5 deletions test/function/samples/plugin-module-information/_config.js
Expand Up @@ -27,7 +27,8 @@ module.exports = {
importers: [],
isEntry: id === ID_MAIN,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
});
},
renderStart() {
Expand Down Expand Up @@ -172,7 +173,8 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
},
{
ast: {
Expand Down Expand Up @@ -247,7 +249,8 @@ module.exports = {
importers: [ID_MAIN, ID_NESTED],
isEntry: false,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
},
{
ast: null,
Expand All @@ -262,7 +265,8 @@ module.exports = {
importers: [ID_FOO],
isEntry: false,
isExternal: true,
meta: {}
meta: {},
syntheticNamedExports: false
},
{
ast: {
Expand Down Expand Up @@ -340,7 +344,8 @@ module.exports = {
importers: [],
isEntry: false,
isExternal: false,
meta: {}
meta: {},
syntheticNamedExports: false
}
]
);
Expand Down
Expand Up @@ -9,6 +9,11 @@ module.exports = {
if (id.endsWith('dep.js')) {
return { code, syntheticNamedExports: true };
}
},
moduleParsed({id, syntheticNamedExports}) {
if (id.endsWith('dep.js')) {
assert.strictEqual(syntheticNamedExports, true);
}
}
}
]
Expand Down
Expand Up @@ -9,6 +9,11 @@ module.exports = {
if (id.endsWith('dep.js')) {
return { code, syntheticNamedExports: '__synthetic' };
}
},
moduleParsed({id, syntheticNamedExports}) {
if (id.endsWith('dep.js')) {
assert.strictEqual(syntheticNamedExports, '__synthetic');
}
}
}
]
Expand Down