From 9c9af6dbbda9912f81dbd4cccfbcd854303e50b5 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 8 Mar 2015 02:49:58 +1100 Subject: [PATCH] add utility.removeClass tests and move parentPath setting to setContext - fixes #967 --- src/babel/traversal/path.js | 24 +++++++++---------- .../utility.remove-console/nested/actual.js | 3 +++ .../utility.remove-console/nested/expected.js | 3 +++ .../utility.remove-console/options.json | 3 +++ .../top-level/actual.js | 1 + .../top-level/expected.js | 1 + 6 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 test/fixtures/transformation/utility.remove-console/nested/actual.js create mode 100644 test/fixtures/transformation/utility.remove-console/nested/expected.js create mode 100644 test/fixtures/transformation/utility.remove-console/options.json create mode 100644 test/fixtures/transformation/utility.remove-console/top-level/actual.js create mode 100644 test/fixtures/transformation/utility.remove-console/top-level/expected.js diff --git a/src/babel/traversal/path.js b/src/babel/traversal/path.js index 0d8e80e7e9..fe31243d6e 100644 --- a/src/babel/traversal/path.js +++ b/src/babel/traversal/path.js @@ -4,11 +4,10 @@ import Scope from "./scope"; import t from "../types"; export default class TraversalPath { - constructor(parentPath, parent, container) { - this.parentPath = parentPath; - this.container = container; - this.parent = parent; - this.data = {}; + constructor(parent, container) { + this.container = container; + this.parent = parent; + this.data = {}; } static get(parentPath, context, parent, container, key) { @@ -25,11 +24,11 @@ export default class TraversalPath { } if (!path) { - path = new TraversalPath(parentPath, parent, container); + path = new TraversalPath(parent, container); paths.push(path); } - path.setContext(context, key); + path.setContext(parentPath, context, key); return path; } @@ -57,15 +56,16 @@ export default class TraversalPath { this.scope = TraversalPath.getScope(this.node, this.parent, this.context.scope); } - setContext(context, key) { + setContext(parentPath, context, key) { this.shouldRemove = false; this.shouldSkip = false; this.shouldStop = false; - this.context = context; - this.state = context.state; - this.opts = context.opts; - this.key = key; + this.parentPath = parentPath; + this.context = context; + this.state = context.state; + this.opts = context.opts; + this.key = key; this.setScope(); } diff --git a/test/fixtures/transformation/utility.remove-console/nested/actual.js b/test/fixtures/transformation/utility.remove-console/nested/actual.js new file mode 100644 index 0000000000..579864e91c --- /dev/null +++ b/test/fixtures/transformation/utility.remove-console/nested/actual.js @@ -0,0 +1,3 @@ +function foo() { + console.log("foo"); +} diff --git a/test/fixtures/transformation/utility.remove-console/nested/expected.js b/test/fixtures/transformation/utility.remove-console/nested/expected.js new file mode 100644 index 0000000000..f7c08d93da --- /dev/null +++ b/test/fixtures/transformation/utility.remove-console/nested/expected.js @@ -0,0 +1,3 @@ +"use strict"; + +function foo() {} diff --git a/test/fixtures/transformation/utility.remove-console/options.json b/test/fixtures/transformation/utility.remove-console/options.json new file mode 100644 index 0000000000..1fbb38a1ae --- /dev/null +++ b/test/fixtures/transformation/utility.remove-console/options.json @@ -0,0 +1,3 @@ +{ + "optional": ["utility.removeConsole"] +} diff --git a/test/fixtures/transformation/utility.remove-console/top-level/actual.js b/test/fixtures/transformation/utility.remove-console/top-level/actual.js new file mode 100644 index 0000000000..85ce559e8f --- /dev/null +++ b/test/fixtures/transformation/utility.remove-console/top-level/actual.js @@ -0,0 +1 @@ +console.log("foo"); diff --git a/test/fixtures/transformation/utility.remove-console/top-level/expected.js b/test/fixtures/transformation/utility.remove-console/top-level/expected.js new file mode 100644 index 0000000000..3918c74e44 --- /dev/null +++ b/test/fixtures/transformation/utility.remove-console/top-level/expected.js @@ -0,0 +1 @@ +"use strict";