prevent possibility of conflicts with __file

pull/1501/head
Rich Harris 6 years ago
parent 48c885bcbb
commit 04ef203787

@ -118,6 +118,7 @@ export default class Compiler {
usesRefs: boolean;
file: string;
fileVar: string;
locate: (c: number) => { line: number, column: number };
stylesheet: Stylesheet;
@ -182,6 +183,8 @@ export default class Compiler {
this.aliases = new Map();
this.usedNames = new Set();
this.fileVar = options.dev && this.getUniqueName('file');
this.computations = [];
this.templateProperties = {};

@ -101,7 +101,7 @@ export default function dom(
}
if (compiler.options.dev) {
builder.addLine(`const __file = ${JSON.stringify(compiler.file)};`);
builder.addLine(`const ${compiler.fileVar} = ${JSON.stringify(compiler.file)};`);
}
const css = compiler.stylesheet.render(options.filename, !compiler.customElement);

@ -399,7 +399,7 @@ export default class Element extends Node {
if (this.compiler.options.dev) {
const loc = this.compiler.locate(this.start);
block.builders.hydrate.addLine(
`@addLoc(${this.var}, __file, ${loc.line}, ${loc.column}, ${this.start});`
`@addLoc(${this.var}, ${this.compiler.fileVar}, ${loc.line}, ${loc.column}, ${this.start});`
);
}
}

@ -1,6 +1,6 @@
/* src/Main.html generated by Svelte vx.y.z */
const __file = "src/Main.html";
const file = "src/Main.html";
function create_main_fragment(component, ctx) {
var p, text;
@ -9,7 +9,7 @@ function create_main_fragment(component, ctx) {
c: function create() {
p = createElement("p");
text = createText("Hello world!");
addLoc(p, __file, 0, 0, 0);
addLoc(p, file, 0, 0, 0);
},
m: function mount(target, anchor) {

@ -165,7 +165,7 @@ function bar({ foo }) {
return foo * 2;
}
const __file = undefined;
const file = undefined;
function create_main_fragment(component, ctx) {
var p, text_value = ctx.Math.max(0, ctx.foo), text, text_1, text_2;
@ -176,7 +176,7 @@ function create_main_fragment(component, ctx) {
text = createText(text_value);
text_1 = createText("\n\t");
text_2 = createText(ctx.bar);
addLoc(p, __file, 0, 0, 0);
addLoc(p, file, 0, 0, 0);
},
m: function mount(target, anchor) {

@ -5,7 +5,7 @@ function bar({ foo }) {
return foo * 2;
}
const __file = undefined;
const file = undefined;
function create_main_fragment(component, ctx) {
var p, text_value = ctx.Math.max(0, ctx.foo), text, text_1, text_2;
@ -16,7 +16,7 @@ function create_main_fragment(component, ctx) {
text = createText(text_value);
text_1 = createText("\n\t");
text_2 = createText(ctx.bar);
addLoc(p, __file, 0, 0, 0);
addLoc(p, file, 0, 0, 0);
},
m: function mount(target, anchor) {

Loading…
Cancel
Save