sourcemap markup

pull/6427/head
tanhauhau 5 years ago
parent 17c5402e31
commit 4e467809ce

@ -19,7 +19,7 @@ import { add_event_handler } from '../shared/add_event_handlers';
import { add_action } from '../shared/add_actions';
import bind_this from '../shared/bind_this';
import { is_head } from '../shared/is_head';
import { Identifier } from 'estree';
import { Identifier, ExpressionStatement, CallExpression } from 'estree';
import EventHandler from './EventHandler';
import { extract_names } from 'periscopic';
import Action from '../../../nodes/Action';
@ -263,15 +263,23 @@ export default class ElementWrapper extends Wrapper {
}
if (parent_node) {
block.chunks.mount.push(
b`@append(${parent_node}, ${node});`
);
const append = b`@append(${parent_node}, ${node});`;
((append[0] as ExpressionStatement).expression as CallExpression).callee.loc = {
start: this.renderer.locate(this.node.start),
end: this.renderer.locate(this.node.end)
};
block.chunks.mount.push(append);
if (is_head(parent_node)) {
block.chunks.destroy.push(b`@detach(${node});`);
}
} else {
block.chunks.mount.push(b`@insert(#target, ${node}, #anchor);`);
const insert = b`@insert(#target, ${node}, #anchor);`;
((insert[0] as ExpressionStatement).expression as CallExpression).callee.loc = {
start: this.renderer.locate(this.node.start),
end: this.renderer.locate(this.node.end)
};
block.chunks.mount.push(insert);
// TODO we eventually need to consider what happens to elements
// that belong to the same outgroup as an outroing element...

@ -0,0 +1,2 @@
<h1>decoded-sourcemap</h1>
<div>replace me</div>

@ -0,0 +1,34 @@
export function test({ assert, input, js }) {
let expected;
let start;
let actual;
start = js.locate('insert(target, h1');
expected = input.locate('<h1');
actual = js.mapConsumer.originalPositionFor({
line: start.line + 1,
column: start.column
});
assert.deepEqual(actual, {
source: 'input.svelte',
name: null,
line: expected.line + 1,
column: expected.column
});
start = js.locate('insert(target, div');
expected = input.locate('<div');
actual = js.mapConsumer.originalPositionFor({
line: start.line + 1,
column: start.column
});
assert.deepEqual(actual, {
source: 'input.svelte',
name: null,
line: expected.line + 1,
column: expected.column
});
}
Loading…
Cancel
Save