fix some more tests

pull/1864/head
Rich Harris 7 years ago
parent bc0f381b34
commit ed39c85f5d

@ -168,7 +168,7 @@ export default class Component {
const helpers = new Set(); const helpers = new Set();
// TODO use same regex for both // 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 (sigil === '@') {
if (name in internal) { if (name in internal) {
if (options.dev && `${name}Dev` in internal) name = `${name}Dev`; if (options.dev && `${name}Dev` in internal) name = `${name}Dev`;
@ -178,10 +178,6 @@ export default class Component {
return this.alias(name); return this.alias(name);
} }
if (sigil === '%') {
return this.templateVars.get(name);
}
return sigil.slice(1) + name; return sigil.slice(1) + name;
}); });

@ -8,6 +8,7 @@ import addToSet from '../../../utils/addToSet';
import globalWhitelist from '../../../utils/globalWhitelist'; import globalWhitelist from '../../../utils/globalWhitelist';
import deindent from '../../../utils/deindent'; import deindent from '../../../utils/deindent';
import Wrapper from '../../render-dom/wrappers/shared/Wrapper'; import Wrapper from '../../render-dom/wrappers/shared/Wrapper';
import sanitize from '../../../utils/sanitize';
const binaryOperators: Record<string, number> = { const binaryOperators: Record<string, number> = {
'**': 15, '**': 15,
@ -194,7 +195,9 @@ export default class Expression {
// the return value doesn't matter // 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 const args = contextual_dependencies.size > 0
? [`{ ${[...contextual_dependencies].join(', ')} }`] ? [`{ ${[...contextual_dependencies].join(', ')} }`]

@ -5,10 +5,7 @@ import Slot from '../../nodes/Slot';
import { quotePropIfNecessary } from '../../../utils/quoteIfNecessary'; import { quotePropIfNecessary } from '../../../utils/quoteIfNecessary';
import FragmentWrapper from './Fragment'; import FragmentWrapper from './Fragment';
import deindent from '../../../utils/deindent'; import deindent from '../../../utils/deindent';
import sanitize from '../../../utils/sanitize';
function sanitize(name) {
return name.replace(/[^a-zA-Z]+/g, '_').replace(/^_/, '').replace(/_$/, '');
}
export default class SlotWrapper extends Wrapper { export default class SlotWrapper extends Wrapper {
node: Slot; node: Slot;

@ -0,0 +1,3 @@
export default function sanitize(name) {
return name.replace(/[^a-zA-Z]+/g, '_').replace(/^_/, '').replace(/_$/, '');
}

@ -3,7 +3,7 @@ export function stringify(data: string, options = {}) {
} }
export function escape(data: string, { onlyEscapeAtSymbol = false } = {}) { 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]; return match + match[0];
}); });
} }

@ -6,13 +6,13 @@ export default {
nestedTransitions: true, nestedTransitions: true,
test(assert, component, target) { test(assert, component, target) {
const Foo = component.Foo; const Bar = component.Bar;
component.Foo = null; component.Bar = null;
assert.htmlEqual(target.innerHTML, ``); assert.htmlEqual(target.innerHTML, ``);
component.Foo = Foo; component.Bar = Bar;
assert.htmlEqual(target.innerHTML, ` assert.htmlEqual(target.innerHTML, `
<p>Foo</p> <p>Foo</p>

@ -1,5 +1,7 @@
<script> <script>
import Foo from './Foo.html'; import Foo from './Foo.html';
export let Bar = Foo;
</script> </script>
<svelte:component this={Foo}/> <svelte:component this={Bar}/>

@ -9,7 +9,7 @@ export default {
let answer; let answer;
component.$on('foo', event => { component.$on('foo', event => {
answer = event.answer; answer = event.detail.answer;
}); });
button.dispatchEvent(event); button.dispatchEvent(event);

@ -1,6 +1,6 @@
export default { export default {
props: { 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', html: '1, 3, 5, 7, 9',

@ -1 +1 @@
{ numbers.filter( x => x % 2 ).join( ', ' ) } {numbers.filter(x => x % 2).join(', ')}
Loading…
Cancel
Save