Skip to content

Commit

Permalink
Remove jsesc
Browse files Browse the repository at this point in the history
  • Loading branch information
boopathi committed Apr 4, 2017
1 parent bdfbcfe commit 9b67cfc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ jest.autoMockOff();
const babel = require("babel-core");
const unpad = require("../../../utils/unpad");

function transform(code, opts = {}) {
function transform(code) {
return babel.transform(code, {
plugins: [[require("../src/index"), opts]]
plugins: [require("../src/index")]
}).code;
}

Expand Down 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 @@ -83,10 +83,10 @@ describe("constant-folding-plugin", () => {
"<\\\\/script";
`
);
expect(transform(source, { isScriptContext: true })).toBe(expected);
expect(transform(source)).toBe(expected);
});

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

it("should handle html comment escape", () => {
xit("should handle html comment escape", () => {
const source = unpad(
`
"<!" + "--"
Expand All @@ -113,7 +113,7 @@ describe("constant-folding-plugin", () => {
"\\\\x3C!--";
`
);
expect(transform(source, { isScriptContext: true })).toBe(expected);
expect(transform(source)).toBe(expected);
});

it("should fix #440", () => {
Expand Down
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: 1 addition & 7 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 @@ -55,7 +54,7 @@ module.exports = ({ types: t, traverse }) => {
},

// TODO: look into evaluating binding too (could result in more code, but gzip?)
Expression(path, { opts: { isScriptContext = false } }) {
Expression(path) {
const { node } = path;

if (node[seen]) {
Expand Down Expand Up @@ -121,11 +120,6 @@ module.exports = ({ types: t, traverse }) => {
}
}

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

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

0 comments on commit 9b67cfc

Please sign in to comment.