Browse Source

ensure name suggestions are legal identifiers

ghi-672
Rich Harris 8 years ago
parent
commit
528b692a38
  1. 8
      src/Declaration.js
  2. 3
      test/function/legal-suggested-names/_config.js
  3. 5
      test/function/legal-suggested-names/bar.js
  4. 5
      test/function/legal-suggested-names/foo.js
  5. 5
      test/function/legal-suggested-names/helpers.js
  6. 8
      test/function/legal-suggested-names/main.js

8
src/Declaration.js

@ -1,4 +1,5 @@
import { blank, forOwn, keys } from './utils/object.js'; import { blank, forOwn, keys } from './utils/object.js';
import makeLegalIdentifier from './utils/makeLegalIdentifier.js';
import run from './utils/run.js'; import run from './utils/run.js';
import { SyntheticReference } from './Reference.js'; import { SyntheticReference } from './Reference.js';
@ -17,7 +18,7 @@ export default class Declaration {
} }
this.statement = statement; this.statement = statement;
this.name = null; this.name = node.id ? node.id.name : node.name;
this.exportName = null; this.exportName = null;
this.isParam = isParam; this.isParam = isParam;
@ -33,7 +34,10 @@ export default class Declaration {
addReference ( reference ) { addReference ( reference ) {
reference.declaration = this; reference.declaration = this;
this.name = reference.name; // TODO handle differences of opinion
if ( reference.name !== this.name ) {
this.name = makeLegalIdentifier( reference.name ); // TODO handle differences of opinion
}
if ( reference.isReassignment ) this.isReassigned = true; if ( reference.isReassignment ) this.isReassigned = true;
} }

3
test/function/legal-suggested-names/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'illegal name suggestions are ignored'
};

5
test/function/legal-suggested-names/bar.js

@ -0,0 +1,5 @@
import * as helpers from './helpers.js';
export default function bar ( a ) {
return helpers.typeof( a );
}

5
test/function/legal-suggested-names/foo.js

@ -0,0 +1,5 @@
import * as helpers from './helpers.js';
export default function foo ( a ) {
return helpers.typeof( a );
}

5
test/function/legal-suggested-names/helpers.js

@ -0,0 +1,5 @@
var _typeof = function ( thing ) {
return typeof thing;
};
export { _typeof as typeof };

8
test/function/legal-suggested-names/main.js

@ -0,0 +1,8 @@
import * as helpers from './helpers.js';
import foo from './foo.js';
import bar from './bar.js';
assert.equal( helpers.typeof( foo ), 'function' );
assert.equal( helpers.typeof( bar ), 'function' );
assert.equal( foo( 1 ), 'number' );
assert.equal( bar( 2 ), 'number' );
Loading…
Cancel
Save