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

Only warn about dynamic module workers #73

Merged
merged 2 commits into from
Jun 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ export default class WorkerPlugin {
const handleWorker = workerTypeString => expr => {
const dep = parser.evaluateExpression(expr.arguments[0]);

if (!dep.isString()) {
parser.state.module.warnings.push({
message: `new ${workerTypeString}() will only be bundled if passed a String.`
});
return false;
}

const optsExpr = expr.arguments[1];
let hasInitOptions = false;
let typeModuleExpr;
Expand All @@ -74,8 +67,18 @@ export default class WorkerPlugin {
}

if (!opts || opts.type !== 'module') {
// If an unknown type value is passed, it's probably an error and we can warn the developer:
if (opts.type !== 'classic') {
parser.state.module.warnings.push({
message: `new ${workerTypeString}() will only be bundled if passed options that include { type: 'module' }.${opts ? `\n Received: new ${workerTypeString}()(${JSON.stringify(dep.string)}, ${JSON.stringify(opts)})` : ''}`
});
}
return false;
}

if (!dep.isString()) {
parser.state.module.warnings.push({
message: `new ${workerTypeString}() will only be bundled if passed options that include { type: 'module' }.${opts ? `\n Received: new ${workerTypeString}()(${JSON.stringify(dep.string)}, ${JSON.stringify(opts)})` : ''}`
message: `new ${workerTypeString}("..", { type: "module" }) will only be bundled if passed a String.`
});
return false;
}
Expand Down