From fe3068f779ee1a14745953e9e55d55c37810abff Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 19 Mar 2017 04:45:25 -0400 Subject: [PATCH 1/3] only do special reserved name handling when tag is all lowercase letters --- src/parse/read/expression.js | 2 +- .../generator/samples/attribute-dynamic-reserved/_config.js | 6 +++--- test/generator/samples/attribute-dynamic-reserved/main.html | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/parse/read/expression.js b/src/parse/read/expression.js index 61cebc9cc7..110b6af4ef 100644 --- a/src/parse/read/expression.js +++ b/src/parse/read/expression.js @@ -4,7 +4,7 @@ export default function readExpression ( parser ) { const start = parser.index; const name = parser.readUntil( /\s*}}/ ); - if ( name && /^\w+$/.test( name ) ) { + if ( name && /^[a-z]+$/.test( name ) ) { return { type: 'Identifier', start, diff --git a/test/generator/samples/attribute-dynamic-reserved/_config.js b/test/generator/samples/attribute-dynamic-reserved/_config.js index e14059fec0..e0e349b7bc 100644 --- a/test/generator/samples/attribute-dynamic-reserved/_config.js +++ b/test/generator/samples/attribute-dynamic-reserved/_config.js @@ -3,12 +3,12 @@ export default { class: 'foo' }, - html: `
`, + html: `
123`, test ( assert, component, target ) { component.set({ class: 'bar' }); - assert.equal( target.innerHTML, `
` ); - + assert.equal( target.innerHTML, `
123` ); + component.destroy(); } }; diff --git a/test/generator/samples/attribute-dynamic-reserved/main.html b/test/generator/samples/attribute-dynamic-reserved/main.html index 6b149d165f..47185118e2 100644 --- a/test/generator/samples/attribute-dynamic-reserved/main.html +++ b/test/generator/samples/attribute-dynamic-reserved/main.html @@ -1 +1 @@ -
\ No newline at end of file +
{{123}} From 05e77bf3a801330f553fab6ad67950e783578a0b Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 19 Mar 2017 07:25:43 -0400 Subject: [PATCH 2/3] note different default format for SSR --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e0d96054df..f116e2eeb1 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ The Svelte compiler optionally takes a second argument, an object of configurati | | **Values** | **Description** | **Defaults** | |---|---|---|---| -| `format` | `'es'`, `'amd'`, `'cjs'`, `'umd'`, `'iife'`, `'eval'` | The format to output in the compiled component.
`'es'` - ES6/ES2015 module, suitable for consumption by a bundler
`'amd'` - AMD module
`'cjs'` - CommonJS module
`'iife'` - IIFE-wrapped function defining a global variable, suitable for use directly in browser
`'eval'` - standalone function, suitable for passing to `eval()` | `'es'` | +| `format` | `'es'`, `'amd'`, `'cjs'`, `'umd'`, `'iife'`, `'eval'` | The format to output in the compiled component.
`'es'` - ES6/ES2015 module, suitable for consumption by a bundler
`'amd'` - AMD module
`'cjs'` - CommonJS module
`'iife'` - IIFE-wrapped function defining a global variable, suitable for use directly in browser
`'eval'` - standalone function, suitable for passing to `eval()` | `'es'` for `generate: 'dom'`
`'cjs'` for `generate: 'ssr'` | | `generate` | `'dom'`, `'ssr'` | Whether to generate JavaScript code intended for use on the client (`'dom'`), or for use in server-side rendering (`'ssr'`). | `'dom'` | | `name` | `string` | The name of the constructor in the compiled component. | `'SvelteComponent'` | | `filename` | `string` | The filename to use in sourcemaps and compiler error and warning messages. | `'SvelteComponent.html'` | From c33ee7b56e15cfeef9436ff9153f17fd530bec8e Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 19 Mar 2017 04:00:02 -0400 Subject: [PATCH 3/3] fix removeObjectKey when removing last key in object and it has a trailing comma --- src/generators/dom/index.js | 4 ++-- src/utils/removeObjectKey.js | 2 +- test/generator/samples/imported-renamed-components/main.html | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/generators/dom/index.js b/src/generators/dom/index.js index ebf478f5a2..c0541b8959 100644 --- a/src/generators/dom/index.js +++ b/src/generators/dom/index.js @@ -206,8 +206,8 @@ export default function dom ( parsed, source, options, names ) { } }); if ( hasNonImportedComponent ) { - // remove the specific components which were imported, as we'll refer to them directly - Object.keys( generator.importedComponents ).forEach ( key => { + // remove the specific components that were imported, as we'll refer to them directly + Object.keys( generator.importedComponents ).forEach( key => { removeObjectKey( generator, templateProperties.components.value, key ); }); } else { diff --git a/src/utils/removeObjectKey.js b/src/utils/removeObjectKey.js index cbd75eb1f5..a78a5b6ab2 100644 --- a/src/utils/removeObjectKey.js +++ b/src/utils/removeObjectKey.js @@ -4,6 +4,6 @@ export default function removeObjectKey ( generator, node, key ) { const index = properties.findIndex( property => property.key.type === 'Identifier' && property.key.name === key ); if ( index === -1 ) return; const a = properties[ index ].start; - const b = index < properties.length - 1 ? properties[ index + 1 ].start : properties[ index ].end; + const b = index < properties.length - 1 ? properties[ index + 1 ].start : node.end - 1; generator.code.remove( a, b ); } diff --git a/test/generator/samples/imported-renamed-components/main.html b/test/generator/samples/imported-renamed-components/main.html index 7c25eaceab..a976830378 100644 --- a/test/generator/samples/imported-renamed-components/main.html +++ b/test/generator/samples/imported-renamed-components/main.html @@ -5,6 +5,6 @@ import ComponentTwo from './ComponentTwo.html'; export default { - components: { RenamedComponentOne: ComponentOne, RenamedComponentTwo: ComponentTwo } + components: { RenamedComponentOne: ComponentOne, RenamedComponentTwo: ComponentTwo }, };