diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 6c8394871d..2173356a1a 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -168,7 +168,7 @@ export default class Component { const helpers = new Set(); // TODO use same regex for both - result = result.replace(options.generate === 'ssr' ? /(@+|#+|%+)(\w*(?:-\w*)?)/g : /(%+|@+)(\w*(?:-\w*)?)/g, (match: string, sigil: string, name: string) => { + result = result.replace(options.generate === 'ssr' ? /(@+|#+)(\w*(?:-\w*)?)/g : /(@+)(\w*(?:-\w*)?)/g, (match: string, sigil: string, name: string) => { if (sigil === '@') { if (name in internal) { if (options.dev && `${name}Dev` in internal) name = `${name}Dev`; @@ -178,10 +178,6 @@ export default class Component { return this.alias(name); } - if (sigil === '%') { - return this.templateVars.get(name); - } - return sigil.slice(1) + name; }); diff --git a/src/compile/nodes/shared/Expression.ts b/src/compile/nodes/shared/Expression.ts index 1e911d77f7..77bd17f677 100644 --- a/src/compile/nodes/shared/Expression.ts +++ b/src/compile/nodes/shared/Expression.ts @@ -8,6 +8,7 @@ import addToSet from '../../../utils/addToSet'; import globalWhitelist from '../../../utils/globalWhitelist'; import deindent from '../../../utils/deindent'; import Wrapper from '../../render-dom/wrappers/shared/Wrapper'; +import sanitize from '../../../utils/sanitize'; const binaryOperators: Record = { '**': 15, @@ -194,7 +195,9 @@ export default class Expression { // the return value doesn't matter } - const name = component.getUniqueName(get_function_name(node, owner)); + const name = component.getUniqueName( + sanitize(get_function_name(node, owner)) + ); const args = contextual_dependencies.size > 0 ? [`{ ${[...contextual_dependencies].join(', ')} }`] diff --git a/src/compile/render-dom/wrappers/Slot.ts b/src/compile/render-dom/wrappers/Slot.ts index d12464cc61..33d5f5227b 100644 --- a/src/compile/render-dom/wrappers/Slot.ts +++ b/src/compile/render-dom/wrappers/Slot.ts @@ -5,10 +5,7 @@ import Slot from '../../nodes/Slot'; import { quotePropIfNecessary } from '../../../utils/quoteIfNecessary'; import FragmentWrapper from './Fragment'; import deindent from '../../../utils/deindent'; - -function sanitize(name) { - return name.replace(/[^a-zA-Z]+/g, '_').replace(/^_/, '').replace(/_$/, ''); -} +import sanitize from '../../../utils/sanitize'; export default class SlotWrapper extends Wrapper { node: Slot; diff --git a/src/utils/sanitize.ts b/src/utils/sanitize.ts new file mode 100644 index 0000000000..04cd9732b4 --- /dev/null +++ b/src/utils/sanitize.ts @@ -0,0 +1,3 @@ +export default function sanitize(name) { + return name.replace(/[^a-zA-Z]+/g, '_').replace(/^_/, '').replace(/_$/, ''); +} \ No newline at end of file diff --git a/src/utils/stringify.ts b/src/utils/stringify.ts index 43cbd934c3..dbf8da16c4 100644 --- a/src/utils/stringify.ts +++ b/src/utils/stringify.ts @@ -3,7 +3,7 @@ export function stringify(data: string, options = {}) { } export function escape(data: string, { onlyEscapeAtSymbol = false } = {}) { - return data.replace(onlyEscapeAtSymbol ? /(%+|@+)/g : /(%+|@+|#+)/g, (match: string) => { + return data.replace(onlyEscapeAtSymbol ? /@+/g : /(@+|#+)/g, (match: string) => { return match + match[0]; }); } diff --git a/test/runtime/samples/dynamic-component-nulled-out/_config.js b/test/runtime/samples/dynamic-component-nulled-out/_config.js index 4ddc9440db..fa69d38b88 100644 --- a/test/runtime/samples/dynamic-component-nulled-out/_config.js +++ b/test/runtime/samples/dynamic-component-nulled-out/_config.js @@ -6,13 +6,13 @@ export default { nestedTransitions: true, test(assert, component, target) { - const Foo = component.Foo; + const Bar = component.Bar; - component.Foo = null; + component.Bar = null; assert.htmlEqual(target.innerHTML, ``); - component.Foo = Foo; + component.Bar = Bar; assert.htmlEqual(target.innerHTML, `

Foo

diff --git a/test/runtime/samples/dynamic-component-nulled-out/main.html b/test/runtime/samples/dynamic-component-nulled-out/main.html index 4b3544f505..b98ecb8f7e 100644 --- a/test/runtime/samples/dynamic-component-nulled-out/main.html +++ b/test/runtime/samples/dynamic-component-nulled-out/main.html @@ -1,5 +1,7 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/test/runtime/samples/event-handler-shorthand-dynamic-component/_config.js b/test/runtime/samples/event-handler-shorthand-dynamic-component/_config.js index 065df36d77..3463b5c6f4 100644 --- a/test/runtime/samples/event-handler-shorthand-dynamic-component/_config.js +++ b/test/runtime/samples/event-handler-shorthand-dynamic-component/_config.js @@ -9,7 +9,7 @@ export default { let answer; component.$on('foo', event => { - answer = event.answer; + answer = event.detail.answer; }); button.dispatchEvent(event); diff --git a/test/runtime/samples/function-in-expression/_config.js b/test/runtime/samples/function-in-expression/_config.js index cad7491ad5..94fd3fd648 100644 --- a/test/runtime/samples/function-in-expression/_config.js +++ b/test/runtime/samples/function-in-expression/_config.js @@ -1,6 +1,6 @@ export default { props: { - numbers: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] + numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, html: '1, 3, 5, 7, 9', diff --git a/test/runtime/samples/function-in-expression/main.html b/test/runtime/samples/function-in-expression/main.html index 1f038d771b..895a36e690 100644 --- a/test/runtime/samples/function-in-expression/main.html +++ b/test/runtime/samples/function-in-expression/main.html @@ -1 +1 @@ -{ numbers.filter( x => x % 2 ).join( ', ' ) } \ No newline at end of file +{numbers.filter(x => x % 2).join(', ')} \ No newline at end of file