Skip to content

correctly handle when helper functions have been internally renamed (#538) #553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/generators/dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { walk } from 'estree-walker';
import deindent from '../../utils/deindent.js';
import CodeBuilder from '../../utils/CodeBuilder.js';
import visit from './visit.js';
import { nameMap, sharedMap } from './sharedNames.js';
import Generator from '../Generator.js';
import preprocess from './preprocess.js';
import * as shared from '../../shared/index.js';

class DomGenerator extends Generator {
constructor ( parsed, source, name, options ) {
Expand All @@ -25,7 +25,7 @@ class DomGenerator extends Generator {
}

helper ( name ) {
if ( this.options.dev && `${name}Dev` in shared ) {
if ( this.options.dev && sharedMap.has( `${name}Dev` ) ) {
name = `${name}Dev`;
}

Expand Down Expand Up @@ -275,7 +275,7 @@ export default function dom ( parsed, source, options ) {
);
} else {
generator.uses.forEach( key => {
const str = shared[ key ].toString(); // eslint-disable-line import/namespace
const str = sharedMap.get( key );
const code = new MagicString( str );
const fn = parse( str ).body[0];

Expand All @@ -286,11 +286,12 @@ export default function dom ( parsed, source, options ) {
if ( node._scope ) scope = node._scope;

if ( node.type === 'Identifier' && isReference( node, parent ) && !scope.has( node.name ) ) {
if ( node.name in shared ) {
if ( nameMap.has( node.name ) ) {
// this helper function depends on another one
generator.uses.add( node.name );
const dependency = nameMap.get( node.name );
generator.uses.add( dependency );

const alias = generator.alias( node.name );
const alias = generator.alias( dependency );
if ( alias !== node.name ) code.overwrite( node.start, node.end, alias );
}
}
Expand All @@ -301,7 +302,7 @@ export default function dom ( parsed, source, options ) {
}
});

const alias = generator.alias( fn.id.name );
const alias = generator.alias( key );
if ( alias !== fn.id.name ) code.overwrite( fn.id.start, fn.id.end, alias );

builders.main.addBlock( code.toString() );
Expand Down
12 changes: 12 additions & 0 deletions src/generators/dom/sharedNames.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as shared from '../../shared/index.js';

export const nameMap = new Map();
export const sharedMap = new Map();

Object.keys(shared).forEach( key => {
const value = shared[ key ]; // eslint-disable-line import/namespace
if ( typeof value === 'function' ) {
nameMap.set( value.name, key );
}
sharedMap.set( key, value.toString() );
});