From 1655249d7a9cd9403f868d71c7c0e29b2756f3d8 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 28 Feb 2017 13:07:23 -0500 Subject: [PATCH 1/5] use compileOptions when showing failing code --- test/generate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/generate.js b/test/generate.js index bba18f4d2e..7adba3c61d 100644 --- a/test/generate.js +++ b/test/generate.js @@ -44,7 +44,7 @@ describe( 'generate', () => { try { const source = fs.readFileSync( `test/generator/${dir}/main.html`, 'utf-8' ); - compiled = svelte.compile( source ); + compiled = svelte.compile( source, compileOptions ); } catch ( err ) { if ( config.compileError ) { config.compileError( err ); From 7dff587a06dd88fcd19ce041199a5d41713a513b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 28 Feb 2017 13:08:05 -0500 Subject: [PATCH 2/5] failing test for #222 --- test/generator/deconflict-builtins/_config.js | 8 ++++++++ test/generator/deconflict-builtins/get.js | 3 +++ test/generator/deconflict-builtins/main.html | 13 +++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 test/generator/deconflict-builtins/_config.js create mode 100644 test/generator/deconflict-builtins/get.js create mode 100644 test/generator/deconflict-builtins/main.html diff --git a/test/generator/deconflict-builtins/_config.js b/test/generator/deconflict-builtins/_config.js new file mode 100644 index 0000000000..14927e7ad3 --- /dev/null +++ b/test/generator/deconflict-builtins/_config.js @@ -0,0 +1,8 @@ +export default { + html: `got`, + + test ( assert, component ) { + assert.equal( component.get( 'foo' ), 'got' ); + component.teardown(); + } +}; \ No newline at end of file diff --git a/test/generator/deconflict-builtins/get.js b/test/generator/deconflict-builtins/get.js new file mode 100644 index 0000000000..865e2b1c43 --- /dev/null +++ b/test/generator/deconflict-builtins/get.js @@ -0,0 +1,3 @@ +export default function get () { + return 'got'; +} \ No newline at end of file diff --git a/test/generator/deconflict-builtins/main.html b/test/generator/deconflict-builtins/main.html new file mode 100644 index 0000000000..eb9de7d15f --- /dev/null +++ b/test/generator/deconflict-builtins/main.html @@ -0,0 +1,13 @@ +{{foo}} + + \ No newline at end of file From eb4465958972ed9dbfb03354cdf0113240e56f4c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 28 Feb 2017 14:32:51 -0500 Subject: [PATCH 3/5] add generator.helper method, use it in place of generator.uses[...] --- src/generators/Generator.js | 5 ++++ src/generators/dom/visitors/EachBlock.js | 3 +-- src/generators/dom/visitors/Element.js | 12 ++++------ src/generators/dom/visitors/MustacheTag.js | 3 +-- src/generators/dom/visitors/RawMustacheTag.js | 9 +++----- src/generators/dom/visitors/Text.js | 4 +--- .../attributes/addElementAttributes.js | 23 +++++++------------ .../dom/visitors/attributes/binding/index.js | 6 ++--- 8 files changed, 25 insertions(+), 40 deletions(-) diff --git a/src/generators/Generator.js b/src/generators/Generator.js index 6737f1f99a..44d069d06c 100644 --- a/src/generators/Generator.js +++ b/src/generators/Generator.js @@ -193,6 +193,11 @@ export default class Generator { return counter( this.names ); } + helper ( name ) { + this.uses[ name ] = true; + return name; + } + parseJs () { const { source } = this; const { js } = this.parsed; diff --git a/src/generators/dom/visitors/EachBlock.js b/src/generators/dom/visitors/EachBlock.js index 700e16ef7a..e9e0eb4fd3 100644 --- a/src/generators/dom/visitors/EachBlock.js +++ b/src/generators/dom/visitors/EachBlock.js @@ -151,9 +151,8 @@ export default { ` ); } - generator.uses.teardownEach = true; generator.current.builders.teardown.addBlock( - `teardownEach( ${iterations}, ${isToplevel ? 'detach' : 'false'} );` ); + `${generator.helper( 'teardownEach' )}( ${iterations}, ${isToplevel ? 'detach' : 'false'} );` ); if ( node.else ) { generator.current.builders.teardown.addBlock( deindent` diff --git a/src/generators/dom/visitors/Element.js b/src/generators/dom/visitors/Element.js index b200b9710c..f648a3caf9 100644 --- a/src/generators/dom/visitors/Element.js +++ b/src/generators/dom/visitors/Element.js @@ -61,25 +61,21 @@ export default { if ( local.namespace ) { if ( local.namespace === 'http://www.w3.org/2000/svg' ) { - generator.uses.createSvgElement = true; - render = `var ${name} = createSvgElement( '${node.name}' )`; + render = `var ${name} = ${generator.helper( 'createSvgElement' )}( '${node.name}' )`; } else { render = `var ${name} = document.createElementNS( '${local.namespace}', '${node.name}' );`; } } else { - generator.uses.createElement = true; - render = `var ${name} = createElement( '${node.name}' );`; + render = `var ${name} = ${generator.helper( 'createElement' )}( '${node.name}' );`; } if ( generator.cssId && !generator.elementDepth ) { - generator.uses.setAttribute = true; - render += `\nsetAttribute( ${name}, '${generator.cssId}', '' );`; + render += `\n${generator.helper( 'setAttribute' )}( ${name}, '${generator.cssId}', '' );`; } local.init.addLineAtStart( render ); if ( isToplevel ) { - generator.uses.detachNode = true; - generator.current.builders.detach.addLine( `detachNode( ${name} );` ); + generator.current.builders.detach.addLine( `${generator.helper( 'detachNode' )}( ${name} );` ); } // special case – bound