Skip to content

Commit 80ebc68

Browse files
authored
Merge pull request #47 from inokawa/backtick
Escape backticks
2 parents 41bc3d6 + 53e6362 commit 80ebc68

File tree

8 files changed

+3652
-42
lines changed

8 files changed

+3652
-42
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from "react";
2+
import { webViewRender } from "react-native-react-bridge/lib/web";
3+
import Comp from "./Component";
4+
import "./example.css";
5+
6+
const text = "foo `bar`";
7+
console.log(text);
8+
console.log(`baz`);
9+
10+
const App = () => {
11+
return <Comp />;
12+
};
13+
14+
export default webViewRender(App);

src/plugin/__snapshots__/html.spec.js.snap

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/plugin/__snapshots__/index.spec.js.snap

Lines changed: 3572 additions & 0 deletions
Large diffs are not rendered by default.

src/plugin/__snapshots__/metro.spec.js.snap

Lines changed: 20 additions & 0 deletions
Large diffs are not rendered by default.

src/plugin/html.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { ROOT_ID } from "../common";
22

3+
const escape = (src) => src.replace(/`/g, "\\`");
4+
35
export const createContent = (js) =>
4-
`export default String.raw\`${wrapByHtml(js)}\`;`;
6+
`export default String.raw\`${escape(wrapByHtml(js))}\`;`;
57

68
const wrapByHtml = (js) => `
79
<!DOCTYPE html>

src/plugin/html.spec.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/plugin/index.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as fs from "fs";
2+
import * as path from "path";
3+
import { transform } from "./";
4+
5+
const createPath = (filename) =>
6+
path.join(__dirname, "../../fixtures", filename);
7+
const readFixture = (filename) => fs.readFileSync(filename, "utf-8");
8+
9+
describe("transform", () => {
10+
it("export default", async () => {
11+
const filename = "app-export-default.jsx";
12+
const filePath = createPath(filename);
13+
const src = readFixture(filePath);
14+
expect(
15+
await transform({ filename: filePath, src, options: {} })
16+
).toMatchSnapshot();
17+
});
18+
19+
it("export default with backticks", async () => {
20+
const filename = "app-export-default-with-backticks.jsx";
21+
const filePath = createPath(filename);
22+
const src = readFixture(filePath);
23+
expect(
24+
await transform({ filename: filePath, src, options: {} })
25+
).toMatchSnapshot();
26+
});
27+
28+
it("export default with md", async () => {
29+
const filename = "app-export-default-with-md.jsx";
30+
const filePath = createPath(filename);
31+
const src = readFixture(filePath);
32+
expect(
33+
await transform({ filename: filePath, src, options: {} })
34+
).toMatchSnapshot();
35+
});
36+
});

src/plugin/metro.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ describe("bundle", () => {
6666
expect(res).toMatchSnapshot();
6767
});
6868

69+
it("with backticks", async () => {
70+
const filename = "app-export-default-with-backticks.jsx";
71+
const filePath = resolvePath(filename);
72+
const res = await bundle(filePath);
73+
expect(res).toMatchSnapshot();
74+
});
75+
6976
it("default (preact)", async () => {
7077
const filename = "app-export-default-preact.jsx";
7178
const filePath = resolvePath(filename);

0 commit comments

Comments
 (0)