mirror of https://github.com/lukechilds/rollup.git
Rich-Harris
8 years ago
20 changed files with 205 additions and 95 deletions
@ -1,28 +1,21 @@ |
|||||
import { locate } from 'locate-character'; |
|
||||
import error from '../../../utils/error.js'; |
|
||||
|
|
||||
// TODO tidy this up a bit (e.g. they can both use node.module.imports)
|
// TODO tidy this up a bit (e.g. they can both use node.module.imports)
|
||||
export default function disallowIllegalReassignment ( scope, node ) { |
export default function disallowIllegalReassignment ( scope, node ) { |
||||
if ( node.type === 'MemberExpression' && node.object.type === 'Identifier' ) { |
if ( node.type === 'MemberExpression' && node.object.type === 'Identifier' ) { |
||||
const declaration = scope.findDeclaration( node.object.name ); |
const declaration = scope.findDeclaration( node.object.name ); |
||||
if ( declaration.isNamespace ) { |
if ( declaration.isNamespace ) { |
||||
error({ |
node.module.error({ |
||||
message: `Illegal reassignment to import '${node.object.name}'`, |
code: 'ILLEGAL_NAMESPACE_REASSIGNMENT', |
||||
file: node.module.id, |
message: `Illegal reassignment to import '${node.object.name}'` |
||||
pos: node.start, |
}, node.start ); |
||||
loc: locate( node.module.code, node.start, { offsetLine: 1 }) |
|
||||
}); |
|
||||
} |
} |
||||
} |
} |
||||
|
|
||||
else if ( node.type === 'Identifier' ) { |
else if ( node.type === 'Identifier' ) { |
||||
if ( node.module.imports[ node.name ] && !scope.contains( node.name ) ) { |
if ( node.module.imports[ node.name ] && !scope.contains( node.name ) ) { |
||||
error({ |
node.module.error({ |
||||
message: `Illegal reassignment to import '${node.name}'`, |
code: 'ILLEGAL_REASSIGNMENT', |
||||
file: node.module.id, |
message: `Illegal reassignment to import '${node.name}'` |
||||
pos: node.start, |
}, node.start ); |
||||
loc: locate( node.module.code, node.start, { offsetLine: 1 }) |
|
||||
}); |
|
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
@ -1,8 +1,21 @@ |
|||||
|
var path = require( 'path' ); |
||||
var assert = require( 'assert' ); |
var assert = require( 'assert' ); |
||||
|
|
||||
module.exports = { |
module.exports = { |
||||
description: 'reexporting a missing identifier should print an error', |
description: 'reexporting a missing identifier should print an error', |
||||
error: function ( error ) { |
error: { |
||||
assert.ok( /^'foo' is not exported/.test( error.message ) ); |
code: 'MISSING_EXPORT', |
||||
|
message: `'foo' is not exported by empty.js`, |
||||
|
pos: 9, |
||||
|
loc: { |
||||
|
file: path.resolve( __dirname, 'main.js' ), |
||||
|
line: 1, |
||||
|
column: 9 |
||||
|
}, |
||||
|
frame: ` |
||||
|
1: export { foo as bar } from './empty.js'; |
||||
|
^ |
||||
|
`,
|
||||
|
url: 'https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module' |
||||
} |
} |
||||
}; |
}; |
||||
|
Loading…
Reference in new issue