Merge pull request #3742 from tanhauhau/tanhauhau/remove-component-locator

remove Component.locator
pull/3745/head
Rich Harris 5 years ago committed by GitHub
commit 6d1f163bc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -90,15 +90,6 @@ export default class Component {
file: string;
locate: (c: number) => { line: number; column: number };
// TODO this does the same as component.locate! remove one or the other
locator: (
search: number,
startIndex?: number
) => {
line: number;
column: number;
};
stylesheet: Stylesheet;
aliases: Map<string, Identifier> = new Map();
@ -140,7 +131,7 @@ export default class Component {
.replace(process.cwd(), '')
.replace(/^[/\\]/, '')
: compile_options.filename);
this.locate = getLocator(this.source);
this.locate = getLocator(this.source, { offsetLine: 1 });
// styles
this.stylesheet = new Stylesheet(
@ -438,12 +429,8 @@ export default class Component {
return;
}
if (!this.locator) {
this.locator = getLocator(this.source, { offsetLine: 1 });
}
const start = this.locator(pos.start);
const end = this.locator(pos.end);
const start = this.locate(pos.start);
const end = this.locate(pos.end);
const frame = get_code_frame(this.source, start.line - 1, start.column);
@ -456,7 +443,7 @@ export default class Component {
pos: pos.start,
filename: this.compile_options.filename,
toString: () =>
`${warning.message} (${start.line + 1}:${start.column})\n${frame}`,
`${warning.message} (${start.line}:${start.column})\n${frame}`,
});
}

@ -30,7 +30,6 @@ export default class DebugTagWrapper extends Wrapper {
const { var_lookup } = component;
const start = component.locate(this.node.start + 1);
start.line += 1;
const end = { line: start.line, column: start.column + 6 };
const loc = { start, end };

@ -108,7 +108,6 @@ export default class EachBlockWrapper extends Wrapper {
let c = this.node.start + 2;
while (renderer.component.source[c] !== 'e') c += 1;
const start = renderer.component.locate(c);
start.line += 1;
const end = { line: start.line, column: start.column + 4 };
const length = {
type: 'Identifier',

@ -354,7 +354,7 @@ export default class ElementWrapper extends Wrapper {
if (renderer.options.dev) {
const loc = renderer.locate(this.node.start);
block.chunks.hydrate.push(
b`@add_location(${this.var}, ${renderer.file_var}, ${loc.line}, ${loc.column}, ${this.node.start});`
b`@add_location(${this.var}, ${renderer.file_var}, ${loc.line - 1}, ${loc.column}, ${this.node.start});`
);
}
}

@ -26,7 +26,7 @@ export default function create_debugging_comment(
}
const start = locate(c);
const loc = `(${start.line + 1}:${start.column})`;
const loc = `(${start.line}:${start.column})`;
return `${loc} ${source.slice(c, d)}`.replace(/\s/g, ' ');
}

@ -12,5 +12,5 @@ export default function(node: DebugTag, renderer: Renderer, options: RenderOptio
${node.expressions.map(e => p`${e.node.name}`)}
}`;
renderer.add_expression(x`@debug(${filename ? x`"${filename}"` : x`null`}, ${line}, ${column}, ${obj})`);
renderer.add_expression(x`@debug(${filename ? x`"${filename}"` : x`null`}, ${line - 1}, ${column}, ${obj})`);
}

Loading…
Cancel
Save