From c295fc9018b6f568fa06f7f504373bad810a6796 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 11 Aug 2018 18:49:46 -0400 Subject: [PATCH 1/2] add sourcemaps to debug tags --- src/compile/nodes/DebugTag.ts | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/compile/nodes/DebugTag.ts b/src/compile/nodes/DebugTag.ts index 5a273bdf71..e70d6a33a2 100644 --- a/src/compile/nodes/DebugTag.ts +++ b/src/compile/nodes/DebugTag.ts @@ -7,13 +7,10 @@ import addToSet from '../../utils/addToSet'; export default class DebugTag extends Node { expressions: Expression[]; - shouldSkip: boolean; constructor(compiler, parent, scope, info) { super(compiler, parent, scope, info); - this.shouldSkip = !compiler.options.dev; - this.expressions = info.identifiers.map(node => { return new Expression(compiler, parent, scope, node); }); @@ -24,13 +21,26 @@ export default class DebugTag extends Node { parentNode: string, parentNodes: string, ) { - if (this.shouldSkip) return; + if (!this.compiler.options.dev) return; + + const { code } = this.compiler; // Debug all if (this.expressions.length === 0) { - block.builders.create.addLine('debugger;'); - block.builders.update.addLine('debugger;'); + code.overwrite(this.start + 1, this.start + 7, 'debugger', { + storeName: true + }); + const statement = `[✂${this.start + 1}-${this.start + 7}✂];`; + + block.builders.create.addLine(statement); + block.builders.update.addLine(statement); } else { + const { code } = this.compiler; + code.overwrite(this.start + 1, this.start + 7, 'log', { + storeName: true + }); + const log = `[✂${this.start + 1}-${this.start + 7}✂]`; + const dependencies = new Set(); this.expressions.forEach(expression => { addToSet(dependencies, expression.dependencies); @@ -43,15 +53,17 @@ export default class DebugTag extends Node { block.builders.update.addBlock(deindent` if (${condition}) { const { ${identifiers} } = ctx; - console.log({ ${identifiers} }); + console.${log}({ ${identifiers} }); debugger; } `); block.builders.create.addBlock(deindent` - const { ${identifiers} } = ctx; - console.log({ ${identifiers} }); - debugger; + { + const { ${identifiers} } = ctx; + console.${log}({ ${identifiers} }); + debugger; + } `); } } From d56b0b007ec0332738952d76567bad2c8f6cf378 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 11 Aug 2018 18:52:01 -0400 Subject: [PATCH 2/2] update tests --- .../samples/debug-foo-bar-baz-things/expected-bundle.js | 8 +++++--- test/js/samples/debug-foo-bar-baz-things/expected.js | 8 +++++--- test/js/samples/debug-foo/expected-bundle.js | 8 +++++--- test/js/samples/debug-foo/expected.js | 8 +++++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/test/js/samples/debug-foo-bar-baz-things/expected-bundle.js b/test/js/samples/debug-foo-bar-baz-things/expected-bundle.js index 873b28aa2b..a6c539929c 100644 --- a/test/js/samples/debug-foo-bar-baz-things/expected-bundle.js +++ b/test/js/samples/debug-foo-bar-baz-things/expected-bundle.js @@ -259,9 +259,11 @@ function create_each_block(component, ctx) { text = createText(text_value); text_1 = createText("\n\t"); - const { foo, bar, baz, thing } = ctx; - console.log({ foo, bar, baz, thing }); - debugger; + { + const { foo, bar, baz, thing } = ctx; + console.log({ foo, bar, baz, thing }); + debugger; + } addLoc(span, file, 1, 1, 25); }, diff --git a/test/js/samples/debug-foo-bar-baz-things/expected.js b/test/js/samples/debug-foo-bar-baz-things/expected.js index eb8c70bac6..d57c4d7546 100644 --- a/test/js/samples/debug-foo-bar-baz-things/expected.js +++ b/test/js/samples/debug-foo-bar-baz-things/expected.js @@ -86,9 +86,11 @@ function create_each_block(component, ctx) { text = createText(text_value); text_1 = createText("\n\t"); - const { foo, bar, baz, thing } = ctx; - console.log({ foo, bar, baz, thing }); - debugger; + { + const { foo, bar, baz, thing } = ctx; + console.log({ foo, bar, baz, thing }); + debugger; + } addLoc(span, file, 1, 1, 25); }, diff --git a/test/js/samples/debug-foo/expected-bundle.js b/test/js/samples/debug-foo/expected-bundle.js index d4fd9ffaec..8e2147c322 100644 --- a/test/js/samples/debug-foo/expected-bundle.js +++ b/test/js/samples/debug-foo/expected-bundle.js @@ -259,9 +259,11 @@ function create_each_block(component, ctx) { text = createText(text_value); text_1 = createText("\n\t"); - const { foo } = ctx; - console.log({ foo }); - debugger; + { + const { foo } = ctx; + console.log({ foo }); + debugger; + } addLoc(span, file, 1, 1, 25); }, diff --git a/test/js/samples/debug-foo/expected.js b/test/js/samples/debug-foo/expected.js index 214ec7486e..ce2028e66e 100644 --- a/test/js/samples/debug-foo/expected.js +++ b/test/js/samples/debug-foo/expected.js @@ -86,9 +86,11 @@ function create_each_block(component, ctx) { text = createText(text_value); text_1 = createText("\n\t"); - const { foo } = ctx; - console.log({ foo }); - debugger; + { + const { foo } = ctx; + console.log({ foo }); + debugger; + } addLoc(span, file, 1, 1, 25); },