Browse Source

tweak message

legacy-quote-reserved-properties
Rich-Harris 8 years ago
parent
commit
4040022443
  1. 8
      src/ast/nodes/ThisExpression.js
  2. 9
      test/function/warn-on-top-level-this/_config.js

8
src/ast/nodes/ThisExpression.js

@ -1,6 +1,8 @@
import Node from '../Node.js'; import Node from '../Node.js';
import getLocation from '../../utils/getLocation.js'; import getLocation from '../../utils/getLocation.js';
const warning = `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten. See https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined for more information`;
export default class ThisExpression extends Node { export default class ThisExpression extends Node {
initialise ( scope ) { initialise ( scope ) {
const lexicalBoundary = scope.findLexicalBoundary(); const lexicalBoundary = scope.findLexicalBoundary();
@ -8,9 +10,9 @@ export default class ThisExpression extends Node {
if ( lexicalBoundary.isModuleScope ) { if ( lexicalBoundary.isModuleScope ) {
this.alias = this.module.context; this.alias = this.module.context;
if ( this.alias === 'undefined' ) { if ( this.alias === 'undefined' ) {
const location = getLocation(this.module.code, this.module.ast.end); const { line, column } = getLocation( this.module.code, this.start );
const detail = `${this.module.id}, line: ${location.line}, column: ${location.column}`; const detail = `${this.module.id} (${line}:${column + 1})`; // use one-based column number convention
this.module.bundle.onwarn( `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten (in ${detail})`); this.module.bundle.onwarn( `${detail} ${warning}` );
} }
} }
} }

9
test/function/warn-on-top-level-this/_config.js

@ -1,13 +1,12 @@
const assert = require( 'assert' ); const assert = require( 'assert' );
module.exports = { module.exports = {
solo: true,
description: 'warns on top-level this (#770)', description: 'warns on top-level this (#770)',
warnings: warnings => { warnings: warnings => {
const message = `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten`; assert.deepEqual( warnings, [
assert.equal(warnings.length, 1); `main.js (3:1) The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten. See https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined for more information`
assert.equal(warnings[0].indexOf(message), 0); ]);
assert(warnings[0].match(/\(in.*warn-on-top-level-this.*\)/));
assert(warnings[0].match(/line: 4, column: 0/));
}, },
runtimeError: err => { runtimeError: err => {
assert.equal( err.message, `Cannot set property 'foo' of undefined` ); assert.equal( err.message, `Cannot set property 'foo' of undefined` );

Loading…
Cancel
Save