Skip to content

Commit

Permalink
Remove jsesc (#490)
Browse files Browse the repository at this point in the history
* Make jsesc isScriptContext optional

+ Adds option isScriptContext to constant folding plugin
+ Fix #440, fix #413
+ Related #384, #382

* Remove jsesc
  • Loading branch information
boopathi authored Apr 6, 2017
1 parent b953181 commit 2af84b6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe("constant-folding-plugin", () => {
expect(transform(source)).toBe(source);
});

it("should handle script escape", () => {
xit("should handle script escape", () => {
const source = unpad(
`
"</" + "script"
Expand All @@ -86,7 +86,7 @@ describe("constant-folding-plugin", () => {
expect(transform(source)).toBe(expected);
});

it("should handle style escape", () => {
xit("should handle style escape", () => {
const source = unpad(
`
"</" + "style"
Expand All @@ -101,7 +101,7 @@ describe("constant-folding-plugin", () => {
expect(transform(source)).toBe(expected);
});

it("should handle html comment escape", () => {
xit("should handle html comment escape", () => {
const source = unpad(
`
"<!" + "--"
Expand All @@ -115,4 +115,18 @@ describe("constant-folding-plugin", () => {
);
expect(transform(source)).toBe(expected);
});

it("should fix #440", () => {
const source = unpad(
`
var x = "'cool'" + "test";
`
);
const expected = unpad(
`
var x = "'cool'test";
`
);
expect(transform(source)).toBe(expected);
});
});
6 changes: 2 additions & 4 deletions packages/babel-plugin-minify-constant-folding/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
"babel-plugin"
],
"dependencies": {
"babel-helper-evaluate-path": "^0.0.3",
"jsesc": "^2.4.0"
},
"devDependencies": {}
"babel-helper-evaluate-path": "^0.0.3"
}
}
8 changes: 0 additions & 8 deletions packages/babel-plugin-minify-constant-folding/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use strict";

const evaluate = require("babel-helper-evaluate-path");
const jsesc = require("jsesc");

module.exports = ({ types: t, traverse }) => {
const seen = Symbol("seen");
Expand Down Expand Up @@ -121,13 +120,6 @@ module.exports = ({ types: t, traverse }) => {
}
}

// https://github.com/babel/babili/issues/382
if (typeof res.value === "string") {
res.value = jsesc(res.value, {
isScriptContext: true
});
}

const node = t.valueToNode(res.value);
node[seen] = true;
path.replaceWith(node);
Expand Down

0 comments on commit 2af84b6

Please sign in to comment.