diff --git a/src/generators/dom/index.js b/src/generators/dom/index.js index ea2bc706b81c..4ee174ce8020 100644 --- a/src/generators/dom/index.js +++ b/src/generators/dom/index.js @@ -5,11 +5,10 @@ import isReference from '../../utils/isReference.js'; import { walk } from 'estree-walker'; import deindent from '../../utils/deindent.js'; import CodeBuilder from '../../utils/CodeBuilder.js'; -import toSource from '../../utils/toSource.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 ) { @@ -26,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`; } @@ -276,8 +275,7 @@ export default function dom ( parsed, source, options ) { ); } else { generator.uses.forEach( key => { - const value = shared[ key ]; // eslint-disable-line import/namespace - const str = toSource( value ); + const str = sharedMap.get( key ); const code = new MagicString( str ); const fn = parseExpressionAt( str, 0 ); @@ -288,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 ); } } diff --git a/src/generators/dom/sharedNames.js b/src/generators/dom/sharedNames.js new file mode 100644 index 000000000000..347969fe5f08 --- /dev/null +++ b/src/generators/dom/sharedNames.js @@ -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() ); +}); diff --git a/src/generators/dom/visitors/Element/Binding.js b/src/generators/dom/visitors/Element/Binding.js index 2ca07f3f2e6d..83d415cb7455 100644 --- a/src/generators/dom/visitors/Element/Binding.js +++ b/src/generators/dom/visitors/Element/Binding.js @@ -30,7 +30,7 @@ export default function visitBinding ( generator, block, state, node, attribute //
diff --git a/test/runtime/samples/binding-select-initial-value/main.html b/test/runtime/samples/binding-select-initial-value/main.html index d7d02194c8da..ea154022401e 100644 --- a/test/runtime/samples/binding-select-initial-value/main.html +++ b/test/runtime/samples/binding-select-initial-value/main.html @@ -1,9 +1,9 @@selected: {{selected}}
selected: {{selected}}
\ No newline at end of file diff --git a/test/runtime/samples/binding-select-multiple/_config.js b/test/runtime/samples/binding-select-multiple/_config.js index 89b0da96581f..ec4f3dfe4ec0 100644 --- a/test/runtime/samples/binding-select-multiple/_config.js +++ b/test/runtime/samples/binding-select-multiple/_config.js @@ -1,12 +1,12 @@ export default { - skip: true, // selectedOptions doesn't work in JSDOM??? + skip: true, // JSDOM data: { selected: [ 'two', 'three' ] }, html: ` -selected: one
@@ -13,6 +11,10 @@ export default {selected: one
`, + data: { + selected: 'one' + }, + test ( assert, component, target, window ) { const select = target.querySelector( 'select' ); const options = [ ...target.querySelectorAll( 'option' ) ]; diff --git a/test/runtime/samples/select-change-handler/_config.js b/test/runtime/samples/select-change-handler/_config.js index 560061a09cab..015c8182b41c 100644 --- a/test/runtime/samples/select-change-handler/_config.js +++ b/test/runtime/samples/select-change-handler/_config.js @@ -1,6 +1,4 @@ export default { - skip: true, // JSDOM - data: { options: [ { id: 'a' }, { id: 'b' }, { id: 'c' } ], selected: 'b' diff --git a/test/runtime/samples/select-one-way-bind-object/_config.js b/test/runtime/samples/select-one-way-bind-object/_config.js index 946eaabcebbe..0d7ddaccad7a 100644 --- a/test/runtime/samples/select-one-way-bind-object/_config.js +++ b/test/runtime/samples/select-one-way-bind-object/_config.js @@ -1,8 +1,6 @@ const items = [ {}, {} ]; export default { - skip: true, // JSDOM quirks - 'skip-ssr': true, data: {