Skip to content

Commit ab65ba6

Browse files
committed
fix(): dont error about exported function in global
1 parent d5434e3 commit ab65ba6

File tree

8 files changed

+8
-32
lines changed

8 files changed

+8
-32
lines changed

src/compiler/app-core/bundle-app-core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const bundleApp = async (config: d.Config, compilerCtx: d.CompilerCtx, bu
3838
}),
3939
stencilClientPlugin(config),
4040
stencilBuildConditionalsPlugin(build, config.fsNamespace),
41-
globalScriptsPlugin(config, compilerCtx, buildCtx),
41+
globalScriptsPlugin(config, compilerCtx),
4242
componentEntryPlugin(config, compilerCtx, buildCtx, build, buildCtx.entryModules),
4343
config.sys.rollup.plugins.commonjs({
4444
include: /node_modules/,

src/compiler/component-hydrate/bundle-hydrate-app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const bundleHydrateApp = async (config: d.Config, compilerCtx: d.Compiler
3030
}),
3131
stencilHydratePlugin(config),
3232
stencilBuildConditionalsPlugin(build, config.fsNamespace),
33-
globalScriptsPlugin(config, compilerCtx, buildCtx),
33+
globalScriptsPlugin(config, compilerCtx),
3434
componentEntryPlugin(config, compilerCtx, buildCtx, build, buildCtx.entryModules),
3535
config.sys.rollup.plugins.commonjs({
3636
include: /node_modules/,

src/compiler/rollup-plugins/component-entry.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export const componentEntryPlugin = (config: d.Config, compilerCtx: d.CompilerCt
1717
entrys.set(id, entryModule);
1818
return {
1919
id,
20-
moduleSideEffects: false
2120
};
2221
}
2322
}

src/compiler/rollup-plugins/global-scripts.ts

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as d from '../../declarations';
2-
import { buildError, normalizePath } from '@utils';
2+
import { normalizePath } from '@utils';
33
import { Plugin } from 'rollup';
44

55

@@ -17,7 +17,7 @@ export function hasGlobalScriptPaths(config: d.Config, compilerCtx: d.CompilerCt
1717
}
1818

1919

20-
export function globalScriptsPlugin(config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx): Plugin {
20+
export function globalScriptsPlugin(config: d.Config, compilerCtx: d.CompilerCtx): Plugin {
2121
const globalPaths: string[] = [];
2222

2323
if (typeof config.globalScript === 'string') {
@@ -39,7 +39,6 @@ export function globalScriptsPlugin(config: d.Config, compilerCtx: d.CompilerCtx
3939
if (id === GLOBAL_ID) {
4040
return {
4141
id,
42-
moduleSideEffects: true
4342
};
4443
}
4544
return null;
@@ -62,27 +61,12 @@ export function globalScriptsPlugin(config: d.Config, compilerCtx: d.CompilerCtx
6261
transform(code, id) {
6362
id = normalizePath(id);
6463
if (globalPaths.includes(id)) {
65-
const output = [
66-
INJECT_CONTEXT
67-
];
68-
6964
const program = this.parse(code, {});
7065
const needsDefault = !program.body.some(s => s.type === 'ExportDefaultDeclaration');
71-
72-
if (needsDefault) {
73-
const diagnostic = buildError(buildCtx.diagnostics);
74-
diagnostic.header = `Global Script`;
75-
diagnostic.absFilePath = id;
76-
diagnostic.messageText = `The code to be executed should be placed within a default function that is exported by the global script. Ensure all of the code in the global script is wrapped in the function() that is exported.`;
77-
78-
output.push(`export const fallbackGlobalFn = () => {}`);
79-
output.push(`export default fallbackGlobalFn;`);
80-
81-
} else {
82-
output.push(code);
83-
}
84-
85-
return output.join('\n');
66+
const defaultExport = needsDefault
67+
? '\nexport const globalFn = () => {};\nexport default globalFn;'
68+
: '';
69+
return INJECT_CONTEXT + code + defaultExport;
8670
}
8771
return null;
8872
}

src/compiler/rollup-plugins/loader.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export function loaderPlugin(entries: {[id: string]: string}): Plugin {
88
if (id in entries) {
99
return {
1010
id,
11-
moduleSideEffects: false
1211
};
1312
}
1413
return null;

src/compiler/rollup-plugins/stencil-build-conditionals.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export const NAMESPACE = '${namespace}';
1212
if (id === '@stencil/core/build-conditionals') {
1313
return {
1414
id,
15-
moduleSideEffects: false
1615
};
1716
}
1817
return null;

src/compiler/rollup-plugins/stencil-client.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export function stencilClientPlugin(config: d.Config): Plugin {
99
if (id === '@stencil/core/platform') {
1010
return {
1111
id: config.sys.path.join(config.sys.compiler.distDir, 'client', 'index.mjs'),
12-
moduleSideEffects: false
1312
};
1413
}
1514
return null;

src/compiler/rollup-plugins/stencil-hydrate.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,21 @@ export function stencilHydratePlugin(config: d.Config): Plugin {
99
if (id === '@stencil/core/platform') {
1010
return {
1111
id: config.sys.path.join(config.sys.compiler.distDir, 'hydrate', 'platform.mjs'),
12-
moduleSideEffects: false
1312
};
1413
}
1514
if (id === '@stencil/core/runtime') {
1615
return {
1716
id: config.sys.path.join(config.sys.compiler.distDir, 'runtime', 'index.mjs'),
18-
moduleSideEffects: false
1917
};
2018
}
2119
if (id === '@stencil/core/utils') {
2220
return {
2321
id: config.sys.path.join(config.sys.compiler.distDir, 'utils', 'index.mjs'),
24-
moduleSideEffects: false
2522
};
2623
}
2724
if (id === '@stencil/core') {
2825
return {
2926
id: config.sys.path.join(config.sys.compiler.distDir, 'hydrate', 'platform.mjs'),
30-
moduleSideEffects: false
3127
};
3228
}
3329
return null;

0 commit comments

Comments
 (0)