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)
|
|||
export default function disallowIllegalReassignment ( scope, node ) { |
|||
if ( node.type === 'MemberExpression' && node.object.type === 'Identifier' ) { |
|||
const declaration = scope.findDeclaration( node.object.name ); |
|||
if ( declaration.isNamespace ) { |
|||
error({ |
|||
message: `Illegal reassignment to import '${node.object.name}'`, |
|||
file: node.module.id, |
|||
pos: node.start, |
|||
loc: locate( node.module.code, node.start, { offsetLine: 1 }) |
|||
}); |
|||
node.module.error({ |
|||
code: 'ILLEGAL_NAMESPACE_REASSIGNMENT', |
|||
message: `Illegal reassignment to import '${node.object.name}'` |
|||
}, node.start ); |
|||
} |
|||
} |
|||
|
|||
else if ( node.type === 'Identifier' ) { |
|||
if ( node.module.imports[ node.name ] && !scope.contains( node.name ) ) { |
|||
error({ |
|||
message: `Illegal reassignment to import '${node.name}'`, |
|||
file: node.module.id, |
|||
pos: node.start, |
|||
loc: locate( node.module.code, node.start, { offsetLine: 1 }) |
|||
}); |
|||
node.module.error({ |
|||
code: 'ILLEGAL_REASSIGNMENT', |
|||
message: `Illegal reassignment to import '${node.name}'` |
|||
}, node.start ); |
|||
} |
|||
} |
|||
} |
|||
|
@ -1,8 +1,21 @@ |
|||
var path = require( 'path' ); |
|||
var assert = require( 'assert' ); |
|||
|
|||
module.exports = { |
|||
description: 'reexporting a missing identifier should print an error', |
|||
error: function ( error ) { |
|||
assert.ok( /^'foo' is not exported/.test( error.message ) ); |
|||
error: { |
|||
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