Skip to content

Commit

Permalink
turn namespace assignment error into a warning
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored and lukastaegert committed Jun 13, 2020
1 parent d613137 commit 23f8450
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/ast/nodes/MemberExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE
this.object instanceof Identifier &&
this.scope.findVariable(this.object.name).isNamespace
) {
return this.context.error(
this.scope.findVariable(this.object.name).include();
this.context.warn(
{
code: 'ILLEGAL_NAMESPACE_REASSIGNMENT',
message: `Illegal reassignment to import '${this.object.name}'`
Expand Down
28 changes: 15 additions & 13 deletions test/function/samples/namespace-reassign-import-fails/_config.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
const path = require('path');

module.exports = {
description: 'disallows reassignments to namespace exports',
error: {
code: 'ILLEGAL_NAMESPACE_REASSIGNMENT',
message: `Illegal reassignment to import 'exp'`,
pos: 31,
watchFiles: [path.resolve(__dirname, 'main.js'), path.resolve(__dirname, 'foo.js')],
loc: {
file: path.resolve(__dirname, 'main.js'),
line: 3,
column: 0
},
frame: `
description: 'warns for reassignments to namespace exports',
warnings: [
{
code: 'ILLEGAL_NAMESPACE_REASSIGNMENT',
message: `Illegal reassignment to import 'exp'`,
id: path.resolve(__dirname, 'main.js'),
pos: 31,
loc: {
file: path.resolve(__dirname, 'main.js'),
line: 3,
column: 0
},
frame: `
1: import * as exp from './foo';
2:
3: exp.foo = 2;
^
`
}
}
]
};

// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/namespace-reassign-import-fails
26 changes: 14 additions & 12 deletions test/function/samples/namespace-update-import-fails/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ const path = require('path');

module.exports = {
description: 'disallows updates to namespace exports',
error: {
code: 'ILLEGAL_NAMESPACE_REASSIGNMENT',
message: `Illegal reassignment to import 'exp'`,
pos: 31,
watchFiles: [path.resolve(__dirname, 'main.js'), path.resolve(__dirname, 'foo.js')],
loc: {
file: path.resolve(__dirname, 'main.js'),
line: 3,
column: 0
},
frame: `
warnings: [
{
code: 'ILLEGAL_NAMESPACE_REASSIGNMENT',
message: `Illegal reassignment to import 'exp'`,
id: path.resolve(__dirname, 'main.js'),
pos: 31,
loc: {
file: path.resolve(__dirname, 'main.js'),
line: 3,
column: 0
},
frame: `
1: import * as exp from './foo';
2:
3: exp['foo']++;
^
`
}
}
]
};

// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/namespace-update-import-fails

0 comments on commit 23f8450

Please sign in to comment.