almost all tests passing

pull/3945/head
Rich Harris 6 years ago
parent 23f62d18f8
commit 2c5ddcdb52

@ -167,18 +167,6 @@ export default class Renderer {
const variable = this.component.var_lookup.get(head); const variable = this.component.var_lookup.get(head);
// // TODO this feels woolly. might encounter false positive
// // if each context shadows top-level var
// if (variable) {
// this.component.add_reference(name); // TODO we can probably remove most other occurrences of this
// if (!variable.hoistable) {
// head = x`#ctx[${i}]`;
// }
// } else if (i !== undefined) {
// head = x`#ctx[${i}]`;
// }
if (variable) { if (variable) {
this.component.add_reference(name); // TODO we can probably remove most other occurrences of this this.component.add_reference(name); // TODO we can probably remove most other occurrences of this
} }

@ -6,10 +6,39 @@ import FragmentWrapper from './Fragment';
import { b, p, x } from 'code-red'; import { b, p, x } from 'code-red';
import { sanitize } from '../../../utils/names'; import { sanitize } from '../../../utils/names';
import add_to_set from '../../utils/add_to_set'; import add_to_set from '../../utils/add_to_set';
import get_slot_data from '../../utils/get_slot_data';
import Expression from '../../nodes/shared/Expression'; import Expression from '../../nodes/shared/Expression';
import is_dynamic from './shared/is_dynamic'; import is_dynamic from './shared/is_dynamic';
import { Identifier, ObjectExpression } from 'estree'; import { Identifier, ObjectExpression } from 'estree';
import Attribute from '../../nodes/Attribute';
import { string_literal } from '../../utils/stringify';
function get_slot_data(block: Block, values: Map<string, Attribute>) {
return {
type: 'ObjectExpression',
properties: Array.from(values.values())
.filter(attribute => attribute.name !== 'name')
.map(attribute => {
const value = get_value(block, attribute);
return p`${attribute.name}: ${value}`;
})
};
}
// TODO fairly sure this is duplicated at least once
function get_value(block: Block, attribute: Attribute) {
if (attribute.is_true) return x`true`;
if (attribute.chunks.length === 0) return x`""`;
let value = attribute.chunks
.map(chunk => chunk.type === 'Text' ? string_literal(chunk.data) : chunk.manipulate(block))
.reduce((lhs, rhs) => x`${lhs} + ${rhs}`);
if (attribute.chunks.length > 1 && attribute.chunks[0].type !== 'Text') {
value = x`"" + ${value}`;
}
return value;
}
export default class SlotWrapper extends Wrapper { export default class SlotWrapper extends Wrapper {
node: Slot; node: Slot;

@ -1,7 +1,37 @@
import get_slot_data from '../../utils/get_slot_data';
import Renderer, { RenderOptions } from '../Renderer'; import Renderer, { RenderOptions } from '../Renderer';
import Slot from '../../nodes/Slot'; import Slot from '../../nodes/Slot';
import { x } from 'code-red'; import { x, p } from 'code-red';
import Attribute from '../../nodes/Attribute';
import { string_literal } from '../../utils/stringify';
// TODO this is *almost* but not quite duplicated with non-SSR
function get_slot_data(values: Map<string, Attribute>) {
return {
type: 'ObjectExpression',
properties: Array.from(values.values())
.filter(attribute => attribute.name !== 'name')
.map(attribute => {
const value = get_value(attribute);
return p`${attribute.name}: ${value}`;
})
};
}
// TODO fairly sure this is duplicated at least once
function get_value(attribute: Attribute) {
if (attribute.is_true) return x`true`;
if (attribute.chunks.length === 0) return x`""`;
let value = attribute.chunks
.map(chunk => chunk.type === 'Text' ? string_literal(chunk.data) : chunk.node)
.reduce((lhs, rhs) => x`${lhs} + ${rhs}`);
if (attribute.chunks.length > 1 && attribute.chunks[0].type !== 'Text') {
value = x`"" + ${value}`;
}
return value;
}
export default function(node: Slot, renderer: Renderer, options: RenderOptions) { export default function(node: Slot, renderer: Renderer, options: RenderOptions) {
const slot_data = get_slot_data(node.values); const slot_data = get_slot_data(node.values);

@ -26,7 +26,7 @@ process.on('unhandledRejection', err => {
unhandled_rejection = err; unhandled_rejection = err;
}); });
describe.only("runtime", () => { describe("runtime", () => {
before(() => { before(() => {
svelte = loadSvelte(false); svelte = loadSvelte(false);
svelte$ = loadSvelte(true); svelte$ = loadSvelte(true);

@ -1,31 +1,31 @@
export function test({ assert, smc, locateInSource, locateInGenerated }) { export function test({ assert, smc, locateInSource, locateInGenerated }) {
const expected = locateInSource( 'foo.bar.baz' ); const expected = locateInSource('foo.bar.baz');
let start; let start;
let actual; let actual;
start = locateInGenerated('foo.bar.baz'); start = locateInGenerated('ctx[0].bar.baz');
actual = smc.originalPositionFor({ actual = smc.originalPositionFor({
line: start.line + 1, line: start.line + 1,
column: start.column column: start.column
}); });
assert.deepEqual( actual, { assert.deepEqual(actual, {
source: 'input.svelte', source: 'input.svelte',
name: null, name: null,
line: expected.line + 1, line: expected.line + 1,
column: expected.column column: expected.column
}); });
start = locateInGenerated( 'foo.bar.baz', start.character + 1 ); start = locateInGenerated('ctx[0].bar.baz', start.character + 1);
actual = smc.originalPositionFor({ actual = smc.originalPositionFor({
line: start.line + 1, line: start.line + 1,
column: start.column column: start.column
}); });
assert.deepEqual( actual, { assert.deepEqual(actual, {
source: 'input.svelte', source: 'input.svelte',
name: null, name: null,
line: expected.line + 1, line: expected.line + 1,

Loading…
Cancel
Save