Browse Source

Merge branch 'FredyC-patch-1' of https://github.com/FredyC/rollup into FredyC-FredyC-patch-1

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

5
src/ast/nodes/ThisExpression.js

@ -1,4 +1,5 @@
import Node from '../Node.js';
import getLocation from '../../utils/getLocation.js';
export default class ThisExpression extends Node {
initialise ( scope ) {
@ -7,7 +8,9 @@ export default class ThisExpression extends Node {
if ( lexicalBoundary.isModuleScope ) {
this.alias = this.module.context;
if ( this.alias === 'undefined' ) {
this.module.bundle.onwarn( 'The `this` keyword is equivalent to `undefined` at the top level of an ES module, and has been rewritten' );
const location = getLocation(this.module.code, this.module.ast.end);
const detail = `${this.module.id}, line: ${location.line}, column: ${location.column}`;
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})`);
}
}
}

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

@ -3,9 +3,11 @@ const assert = require( 'assert' );
module.exports = {
description: 'warns on top-level this (#770)',
warnings: warnings => {
assert.deepEqual( warnings, [
'The `this` keyword is equivalent to `undefined` at the top level of an ES module, and has been rewritten'
]);
const message = `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten`;
assert.equal(warnings.length, 1);
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 => {
assert.equal( err.message, `Cannot set property 'foo' of undefined` );

2
test/function/warn-on-top-level-this/main.js

@ -1 +1,3 @@
const someVariableJustToCheckOnCorrectLineNumber = true; // eslint-disable-line
this.foo = 'bar';

Loading…
Cancel
Save