diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index f1ff050636..8ca096166f 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -380,13 +380,19 @@ export default class Generator { getUniqueNameMaker(params: string[]) { const localUsedNames = new Set(params); + + function add(name: string) { + localUsedNames.add(name); + } + + reservedNames.forEach(add); + this.importedNames.forEach(add); + return (name: string) => { if (test) name = `${name}$`; let alias = name; for ( let i = 1; - reservedNames.has(alias) || - this.importedNames.has(alias) || this.usedNames.has(alias) || localUsedNames.has(alias); alias = `${name}_${i++}` diff --git a/src/generators/dom/Block.ts b/src/generators/dom/Block.ts index c0fb7a2c4c..91a92bbe07 100644 --- a/src/generators/dom/Block.ts +++ b/src/generators/dom/Block.ts @@ -251,7 +251,7 @@ export default class Block { if (!this.builders.hydrate.isEmpty()) { properties.addBlock(deindent` - hydrate: function(nodes) { + hydrate: function() { ${this.builders.hydrate} }, `); diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 03e9b0636d..13afa4b93a 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -6,6 +6,7 @@ import { walk } from 'estree-walker'; import deindent from '../../utils/deindent'; import { stringify, escape } from '../../utils/stringify'; import CodeBuilder from '../../utils/CodeBuilder'; +import reservedNames from '../../utils/reservedNames'; import visit from './visit'; import shared from './shared'; import Generator from '../Generator'; @@ -15,6 +16,8 @@ import Block from './Block'; import { version } from '../../../package.json'; import { Parsed, CompileOptions, Node } from '../../interfaces'; +const test = typeof global !== 'undefined' && global.__svelte_test; + export class DomGenerator extends Generator { blocks: (Block|string)[]; readonly: Set; @@ -48,6 +51,33 @@ export class DomGenerator extends Generator { // initial values for e.g. window.innerWidth, if there's a <:Window> meta tag this.metaBindings = []; } + + getUniqueNameMaker(params: string[]) { + const localUsedNames = new Set(params); + + function add(name: string) { + localUsedNames.add(name); + } + + reservedNames.forEach(add); + this.importedNames.forEach(add); + for (const name in shared) { + localUsedNames.add(test ? `${name}$` : name); + } + + return (name: string) => { + if (test) name = `${name}$`; + let alias = name; + for ( + let i = 1; + this.usedNames.has(alias) || + localUsedNames.has(alias); + alias = `${name}_${i++}` + ); + localUsedNames.add(alias); + return alias; + }; + } } export default function dom( diff --git a/src/generators/dom/preprocess.ts b/src/generators/dom/preprocess.ts index b993dcb43f..55d428a452 100644 --- a/src/generators/dom/preprocess.ts +++ b/src/generators/dom/preprocess.ts @@ -195,7 +195,7 @@ const preprocessors = { stripWhitespace: boolean, nextSibling: Node ) => { - node.var = block.getUniqueName(`each_block`); + node.var = block.getUniqueName(`each`); const dependencies = block.findDependencies(node.expression); block.addDependencies(dependencies); @@ -206,7 +206,11 @@ const preprocessors = { indexNames.set(node.context, indexName); const listNames = new Map(block.listNames); - const listName = block.getUniqueName(`each_block_value`); + const listName = block.getUniqueName( + (node.expression.type === 'MemberExpression' && !node.expression.computed) ? node.expression.property.name : + node.expression.type === 'Identifier' ? node.expression.name : + `each_value` + ); listNames.set(node.context, listName); const context = generator.getUniqueName(node.context); diff --git a/src/generators/dom/visitors/EachBlock.ts b/src/generators/dom/visitors/EachBlock.ts index 03c0918ce0..330dba6b81 100644 --- a/src/generators/dom/visitors/EachBlock.ts +++ b/src/generators/dom/visitors/EachBlock.ts @@ -14,16 +14,16 @@ export default function visitEachBlock( elementStack: Node[], componentStack: Node[] ) { - const each_block = node.var; + const each = node.var; const create_each_block = node._block.name; const each_block_value = node._block.listName; - const iterations = block.getUniqueName(`${each_block}_iterations`); + const iterations = block.getUniqueName(`${each}_blocks`); const params = block.params.join(', '); const needsAnchor = node.next ? !isDomNode(node.next, generator) : !state.parentNode; const anchor = needsAnchor - ? block.getUniqueName(`${each_block}_anchor`) + ? block.getUniqueName(`${each}_anchor`) : (node.next && node.next.var) || 'null'; // hack the sourcemap, so that if data is missing the bug @@ -35,7 +35,7 @@ export default function visitEachBlock( const mountOrIntro = node._block.hasIntroMethod ? 'intro' : 'mount'; const vars = { - each_block, + each, create_each_block, each_block_value, length, @@ -67,7 +67,7 @@ export default function visitEachBlock( } if (node.else) { - const each_block_else = generator.getUniqueName(`${each_block}_else`); + const each_block_else = generator.getUniqueName(`${each}_else`); block.builders.init.addLine(`var ${each_block_else} = null;`); @@ -144,7 +144,7 @@ function keyed( node: Node, snippet: string, { - each_block, + each, create_each_block, each_block_value, length, @@ -154,11 +154,11 @@ function keyed( } ) { const key = block.getUniqueName('key'); - const lookup = block.getUniqueName(`${each_block}_lookup`); - const iteration = block.getUniqueName(`${each_block}_iteration`); - const head = block.getUniqueName(`${each_block}_head`); - const last = block.getUniqueName(`${each_block}_last`); - const expected = block.getUniqueName(`${each_block}_expected`); + const lookup = block.getUniqueName(`${each}_lookup`); + const iteration = block.getUniqueName(`${each}_iteration`); + const head = block.getUniqueName(`${each}_head`); + const last = block.getUniqueName(`${each}_last`); + const expected = block.getUniqueName(`${each}_expected`); block.addVariable(lookup, `@blankObject()`); block.addVariable(head); @@ -222,7 +222,7 @@ function keyed( let destroy; if (node._block.hasOutroMethod) { - const fn = block.getUniqueName(`${each_block}_outro`); + const fn = block.getUniqueName(`${each}_outro`); block.builders.init.addBlock(deindent` function ${fn}(iteration) { iteration.outro(function() { @@ -246,7 +246,7 @@ function keyed( } `; } else { - const fn = block.getUniqueName(`${each_block}_destroy`); + const fn = block.getUniqueName(`${each}_destroy`); block.builders.init.addBlock(deindent` function ${fn}(iteration) { iteration.unmount(); diff --git a/src/generators/dom/visitors/Element/EventHandler.ts b/src/generators/dom/visitors/Element/EventHandler.ts index cf71794de4..ded9abc44b 100644 --- a/src/generators/dom/visitors/Element/EventHandler.ts +++ b/src/generators/dom/visitors/Element/EventHandler.ts @@ -1,5 +1,6 @@ import deindent from '../../../../utils/deindent'; import flattenReference from '../../../../utils/flattenReference'; +import validCalleeObjects from '../../../../utils/validCalleeObjects'; import { DomGenerator } from '../../index'; import Block from '../../Block'; import { Node } from '../../../../interfaces'; @@ -23,7 +24,7 @@ export default function visitEventHandler( generator.addSourcemapLocations(attribute.expression); const flattened = flattenReference(attribute.expression.callee); - if (flattened.name !== 'event' && flattened.name !== 'this') { + if (!validCalleeObjects.has(flattened.name)) { // allow event.stopPropagation(), this.select() etc // TODO verify that it's a valid callee (i.e. built-in or declared method) generator.code.prependRight( diff --git a/src/utils/validCalleeObjects.ts b/src/utils/validCalleeObjects.ts new file mode 100644 index 0000000000..ad6070995a --- /dev/null +++ b/src/utils/validCalleeObjects.ts @@ -0,0 +1,3 @@ +const validCalleeObjects = new Set(['this', 'event', 'console']); + +export default validCalleeObjects; \ No newline at end of file diff --git a/src/validate/html/validateEventHandler.ts b/src/validate/html/validateEventHandler.ts index bc0bb23aff..9a22bdd6c8 100644 --- a/src/validate/html/validateEventHandler.ts +++ b/src/validate/html/validateEventHandler.ts @@ -1,6 +1,7 @@ import flattenReference from '../../utils/flattenReference'; import list from '../utils/list'; import { Validator } from '../index'; +import validCalleeObjects from '../../utils/validCalleeObjects'; import { Node } from '../../interfaces'; const validBuiltins = new Set(['set', 'fire', 'destroy']); @@ -20,7 +21,7 @@ export default function validateEventHandlerCallee( const { name } = flattenReference(callee); - if (name === 'this' || name === 'event') return; + if (validCalleeObjects.has(name)) return; if (name === 'refs') { refCallees.push(callee); @@ -33,7 +34,7 @@ export default function validateEventHandlerCallee( ) return; - const validCallees = ['this.*', 'event.*'].concat( + const validCallees = ['this.*', 'event.*', 'console.*'].concat( Array.from(validBuiltins), Array.from(validator.methods.keys()) ); diff --git a/test/helpers.js b/test/helpers.js index 8958235cda..620e359096 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -174,10 +174,10 @@ function capitalise(str) { return str[0].toUpperCase() + str.slice(1); } -export function showOutput(cwd, options = {}) { +export function showOutput(cwd, options = {}, s = svelte) { glob.sync('**/*.html', { cwd }).forEach(file => { if (file[0] === '_') return; - const { code } = svelte.compile( + const { code } = s.compile( fs.readFileSync(`${cwd}/${file}`, 'utf-8'), Object.assign(options, { filename: file, diff --git a/test/js/samples/collapses-text-around-comments/expected-bundle.js b/test/js/samples/collapses-text-around-comments/expected-bundle.js index 29327e012f..16eea4b1da 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -221,7 +221,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { encapsulateStyles(p); }, diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index 2fba8e5f10..58a52bf65a 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -33,7 +33,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { encapsulateStyles(p); }, diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index ca250398fa..12b7d897ee 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -208,7 +208,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { encapsulateStyles(div); }, diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index a47c053601..24ca7471c4 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -24,7 +24,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { encapsulateStyles(div); }, diff --git a/test/js/samples/each-block-changed-check/expected-bundle.js b/test/js/samples/each-block-changed-check/expected-bundle.js index fcaf7c56d9..a9c9399b1f 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -204,18 +204,18 @@ var _actual = (function() { function create_main_fragment(state, component) { var text, p, text_1; - var each_block_value = state.comments; + var comments = state.comments; - var each_block_iterations = []; + var each_blocks = []; - for (var i = 0; i < each_block_value.length; i += 1) { - each_block_iterations[i] = create_each_block(state, each_block_value, each_block_value[i], i, component); + for (var i = 0; i < comments.length; i += 1) { + each_blocks[i] = create_each_block(state, comments, comments[i], i, component); } return { create: function() { - for (var i = 0; i < each_block_iterations.length; i += 1) { - each_block_iterations[i].create(); + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].create(); } text = createText("\n\n"); @@ -224,8 +224,8 @@ function create_main_fragment(state, component) { }, mount: function(target, anchor) { - for (var i = 0; i < each_block_iterations.length; i += 1) { - each_block_iterations[i].mount(target, anchor); + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].mount(target, anchor); } insertNode(text, target, anchor); @@ -234,24 +234,24 @@ function create_main_fragment(state, component) { }, update: function(changed, state) { - var each_block_value = state.comments; + var comments = state.comments; if (changed.comments || changed.elapsed || changed.time) { - for (var i = 0; i < each_block_value.length; i += 1) { - if (each_block_iterations[i]) { - each_block_iterations[i].update(changed, state, each_block_value, each_block_value[i], i); + for (var i = 0; i < comments.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].update(changed, state, comments, comments[i], i); } else { - each_block_iterations[i] = create_each_block(state, each_block_value, each_block_value[i], i, component); - each_block_iterations[i].create(); - each_block_iterations[i].mount(text.parentNode, text); + each_blocks[i] = create_each_block(state, comments, comments[i], i, component); + each_blocks[i].create(); + each_blocks[i].mount(text.parentNode, text); } } - for (; i < each_block_iterations.length; i += 1) { - each_block_iterations[i].unmount(); - each_block_iterations[i].destroy(); + for (; i < each_blocks.length; i += 1) { + each_blocks[i].unmount(); + each_blocks[i].destroy(); } - each_block_iterations.length = each_block_value.length; + each_blocks.length = comments.length; } if (changed.foo) { @@ -260,8 +260,8 @@ function create_main_fragment(state, component) { }, unmount: function() { - for (var i = 0; i < each_block_iterations.length; i += 1) { - each_block_iterations[i].unmount(); + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].unmount(); } detachNode(text); @@ -269,13 +269,13 @@ function create_main_fragment(state, component) { }, destroy: function() { - destroyEach(each_block_iterations, false, 0); + destroyEach(each_blocks, false, 0); } }; } // (1:0) {{#each comments as comment, i}} -function create_each_block(state, each_block_value, comment, i, component) { +function create_each_block(state, comments, comment, i, component) { var div, strong, text, text_1, span, text_2_value = comment.author, text_2, text_3, text_4_value = state.elapsed(comment.time, state.time), text_4, text_5, text_6, raw_value = comment.html, raw_before; return { @@ -294,7 +294,7 @@ function create_each_block(state, each_block_value, comment, i, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { div.className = "comment"; span.className = "meta"; }, @@ -314,7 +314,7 @@ function create_each_block(state, each_block_value, comment, i, component) { raw_before.insertAdjacentHTML("afterend", raw_value); }, - update: function(changed, state, each_block_value, comment, i) { + update: function(changed, state, comments, comment, i) { if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) { text_2.data = text_2_value; } diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 156f9462c7..7e87506196 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -7,18 +7,18 @@ export default (function() { function create_main_fragment(state, component) { var text, p, text_1; - var each_block_value = state.comments; + var comments = state.comments; - var each_block_iterations = []; + var each_blocks = []; - for (var i = 0; i < each_block_value.length; i += 1) { - each_block_iterations[i] = create_each_block(state, each_block_value, each_block_value[i], i, component); + for (var i = 0; i < comments.length; i += 1) { + each_blocks[i] = create_each_block(state, comments, comments[i], i, component); } return { create: function() { - for (var i = 0; i < each_block_iterations.length; i += 1) { - each_block_iterations[i].create(); + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].create(); } text = createText("\n\n"); @@ -27,8 +27,8 @@ function create_main_fragment(state, component) { }, mount: function(target, anchor) { - for (var i = 0; i < each_block_iterations.length; i += 1) { - each_block_iterations[i].mount(target, anchor); + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].mount(target, anchor); } insertNode(text, target, anchor); @@ -37,24 +37,24 @@ function create_main_fragment(state, component) { }, update: function(changed, state) { - var each_block_value = state.comments; + var comments = state.comments; if (changed.comments || changed.elapsed || changed.time) { - for (var i = 0; i < each_block_value.length; i += 1) { - if (each_block_iterations[i]) { - each_block_iterations[i].update(changed, state, each_block_value, each_block_value[i], i); + for (var i = 0; i < comments.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].update(changed, state, comments, comments[i], i); } else { - each_block_iterations[i] = create_each_block(state, each_block_value, each_block_value[i], i, component); - each_block_iterations[i].create(); - each_block_iterations[i].mount(text.parentNode, text); + each_blocks[i] = create_each_block(state, comments, comments[i], i, component); + each_blocks[i].create(); + each_blocks[i].mount(text.parentNode, text); } } - for (; i < each_block_iterations.length; i += 1) { - each_block_iterations[i].unmount(); - each_block_iterations[i].destroy(); + for (; i < each_blocks.length; i += 1) { + each_blocks[i].unmount(); + each_blocks[i].destroy(); } - each_block_iterations.length = each_block_value.length; + each_blocks.length = comments.length; } if (changed.foo) { @@ -63,8 +63,8 @@ function create_main_fragment(state, component) { }, unmount: function() { - for (var i = 0; i < each_block_iterations.length; i += 1) { - each_block_iterations[i].unmount(); + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].unmount(); } detachNode(text); @@ -72,13 +72,13 @@ function create_main_fragment(state, component) { }, destroy: function() { - destroyEach(each_block_iterations, false, 0); + destroyEach(each_blocks, false, 0); } }; } // (1:0) {{#each comments as comment, i}} -function create_each_block(state, each_block_value, comment, i, component) { +function create_each_block(state, comments, comment, i, component) { var div, strong, text, text_1, span, text_2_value = comment.author, text_2, text_3, text_4_value = state.elapsed(comment.time, state.time), text_4, text_5, text_6, raw_value = comment.html, raw_before; return { @@ -97,7 +97,7 @@ function create_each_block(state, each_block_value, comment, i, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { div.className = "comment"; span.className = "meta"; }, @@ -117,7 +117,7 @@ function create_each_block(state, each_block_value, comment, i, component) { raw_before.insertAdjacentHTML("afterend", raw_value); }, - update: function(changed, state, each_block_value, comment, i) { + update: function(changed, state, comments, comment, i) { if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) { text_2.data = text_2_value; } diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index 72d54f01e8..157838a962 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -213,7 +213,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { foo_handler = template.events.foo.call(component, button, function(event) { var state = component.get(); component.foo( state.bar ); diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index 595138f596..e6cfb8bf13 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -29,7 +29,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { foo_handler = template.events.foo.call(component, button, function(event) { var state = component.get(); component.foo( state.bar ); diff --git a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js index a4d325206e..bc5f1d2dc2 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -193,7 +193,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { setStyle(div, "color", state.color); setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); }, diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index f4129ebb38..505a49cb08 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -13,7 +13,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { setStyle(div, "color", state.color); setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); }, diff --git a/test/js/samples/inline-style-optimized-url/expected-bundle.js b/test/js/samples/inline-style-optimized-url/expected-bundle.js index c0a9695ffe..e927618dd5 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -193,7 +193,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); }, diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index 32061f4d60..7a897321d7 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -13,7 +13,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); }, diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 9e2e87fefa..3121c65fa3 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -193,7 +193,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { setStyle(div, "color", state.color); }, diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js index b5d35f85f5..3b062803ec 100644 --- a/test/js/samples/inline-style-optimized/expected.js +++ b/test/js/samples/inline-style-optimized/expected.js @@ -13,7 +13,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { setStyle(div, "color", state.color); }, diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index 032ad03c66..bf96d84f8b 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -195,7 +195,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { div.style.cssText = state.style; div_1.style.cssText = div_1_style_value = "" + state.key + ": " + state.value; }, diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js index b45ff132d2..7d70519f25 100644 --- a/test/js/samples/inline-style-unoptimized/expected.js +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -15,7 +15,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { div.style.cssText = state.style; div_1.style.cssText = div_1_style_value = "" + state.key + ": " + state.value; }, diff --git a/test/js/samples/input-without-blowback-guard/expected-bundle.js b/test/js/samples/input-without-blowback-guard/expected-bundle.js index f6e03fb001..1e66553ac6 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -201,7 +201,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { input.type = "checkbox"; addListener(input, "change", input_change_handler); }, diff --git a/test/js/samples/input-without-blowback-guard/expected.js b/test/js/samples/input-without-blowback-guard/expected.js index 66285864ab..4fa1f54137 100644 --- a/test/js/samples/input-without-blowback-guard/expected.js +++ b/test/js/samples/input-without-blowback-guard/expected.js @@ -17,7 +17,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { input.type = "checkbox"; addListener(input, "change", input_change_handler); }, diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index 80875dada3..ce0814144c 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -195,7 +195,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { setInputType(input, "search"); }, diff --git a/test/js/samples/legacy-input-type/expected.js b/test/js/samples/legacy-input-type/expected.js index 419a68fc55..77d1155b77 100644 --- a/test/js/samples/legacy-input-type/expected.js +++ b/test/js/samples/legacy-input-type/expected.js @@ -13,7 +13,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { setInputType(input, "search"); }, diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js index a0c302b929..ac3e0110b3 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -220,7 +220,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { div.className = "foo"; }, diff --git a/test/js/samples/legacy-quote-class/expected.js b/test/js/samples/legacy-quote-class/expected.js index 05d8d6473d..1870b333fc 100644 --- a/test/js/samples/legacy-quote-class/expected.js +++ b/test/js/samples/legacy-quote-class/expected.js @@ -21,7 +21,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { div.className = "foo"; }, diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index db93324113..6c4b2b6f46 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -244,7 +244,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { component._root._beforecreate.push(audio_progress_loadedmetadata_handler); addListener(audio, "progress", audio_progress_loadedmetadata_handler); diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index 527213251c..fc12b914c3 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -52,7 +52,7 @@ function create_main_fragment(state, component) { this.hydrate(); }, - hydrate: function(nodes) { + hydrate: function() { component._root._beforecreate.push(audio_progress_loadedmetadata_handler); addListener(audio, "progress", audio_progress_loadedmetadata_handler); diff --git a/test/runtime/index.js b/test/runtime/index.js index 0d4fbfd81c..e46f6c8fa7 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -88,7 +88,7 @@ describe("runtime", () => { } } catch (err) { failed.add(dir); - showOutput(cwd, { shared }); // eslint-disable-line no-console + showOutput(cwd, { shared }, svelte); // eslint-disable-line no-console throw err; } } @@ -134,7 +134,7 @@ describe("runtime", () => { try { SvelteComponent = require(`./samples/${dir}/main.html`); } catch (err) { - showOutput(cwd, { shared, hydratable: hydrate }); // eslint-disable-line no-console + showOutput(cwd, { shared, hydratable: hydrate }, svelte); // eslint-disable-line no-console throw err; } @@ -188,12 +188,12 @@ describe("runtime", () => { config.error(assert, err); } else { failed.add(dir); - showOutput(cwd, { shared, hydratable: hydrate }); // eslint-disable-line no-console + showOutput(cwd, { shared, hydratable: hydrate }, svelte); // eslint-disable-line no-console throw err; } } - if (config.show) showOutput(cwd, { shared, hydratable: hydrate }); + if (config.show) showOutput(cwd, { shared, hydratable: hydrate }, svelte); }); } diff --git a/test/runtime/samples/event-handler-console-log/_config.js b/test/runtime/samples/event-handler-console-log/_config.js new file mode 100644 index 0000000000..26d8f9ae29 --- /dev/null +++ b/test/runtime/samples/event-handler-console-log/_config.js @@ -0,0 +1,23 @@ +export default { + data: { + foo: 42 + }, + + html: ` + + `, + + test (assert, component, target, window) { + const button = target.querySelector('button'); + const event = new window.MouseEvent('click'); + + const messages = []; + + const log = console.log; + console.log = msg => messages.push(msg); + button.dispatchEvent(event); + console.log = log; + + assert.deepEqual(messages, [42]); + } +}; diff --git a/test/runtime/samples/event-handler-console-log/main.html b/test/runtime/samples/event-handler-console-log/main.html new file mode 100644 index 0000000000..3500b96373 --- /dev/null +++ b/test/runtime/samples/event-handler-console-log/main.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/validator/samples/method-nonexistent-helper/warnings.json b/test/validator/samples/method-nonexistent-helper/warnings.json index 02512426a1..d090c4df94 100644 --- a/test/validator/samples/method-nonexistent-helper/warnings.json +++ b/test/validator/samples/method-nonexistent-helper/warnings.json @@ -1,5 +1,5 @@ [{ - "message": "'foo' is an invalid callee (should be one of this.*, event.*, set, fire, destroy or bar). 'foo' exists on 'helpers', did you put it in the wrong place?", + "message": "'foo' is an invalid callee (should be one of this.*, event.*, console.*, set, fire, destroy or bar). 'foo' exists on 'helpers', did you put it in the wrong place?", "pos": 18, "loc": { "line": 1, diff --git a/test/validator/samples/method-nonexistent/warnings.json b/test/validator/samples/method-nonexistent/warnings.json index 8debbf8132..d8f4e0e0cf 100644 --- a/test/validator/samples/method-nonexistent/warnings.json +++ b/test/validator/samples/method-nonexistent/warnings.json @@ -1,5 +1,5 @@ [{ - "message": "'foo' is an invalid callee (should be one of this.*, event.*, set, fire, destroy or bar)", + "message": "'foo' is an invalid callee (should be one of this.*, event.*, console.*, set, fire, destroy or bar)", "pos": 18, "loc": { "line": 1, diff --git a/test/validator/samples/window-event-invalid/warnings.json b/test/validator/samples/window-event-invalid/warnings.json index 425c657cb1..20dc4c79fa 100644 --- a/test/validator/samples/window-event-invalid/warnings.json +++ b/test/validator/samples/window-event-invalid/warnings.json @@ -1,5 +1,5 @@ [{ - "message": "'resize' is an invalid callee (should be one of this.*, event.*, set, fire or destroy)", + "message": "'resize' is an invalid callee (should be one of this.*, event.*, console.*, set, fire or destroy)", "loc": { "line": 1, "column": 20