Skip to content
This repository was archived by the owner on Jan 1, 2023. It is now read-only.

Commit 394da6e

Browse files
committed
🐛 convert string includes double quoto
1 parent eb34322 commit 394da6e

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function converter(node: object | null | undefined): unknown {
6868
if (isStringLiteral(node)) {
6969
const { value } = node
7070
if (/"/.test(value)) {
71-
throw new Error('Invalid value is included.')
71+
return value.replace(/"/g, '\\"')
7272
}
7373

7474
return value

src/visitors/object_expression.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const DEFAULT_THRESHOLD = 1024
1414
export function ObjectExpression(
1515
path: NodePath<ObjectExpression>,
1616
state: PluginState
17-
) {
17+
): void {
1818
try {
1919
const obj = converter(path.node)
2020
const json = JSON.stringify(obj)
@@ -23,8 +23,7 @@ export function ObjectExpression(
2323
// it simply isn't worth it to convert into the AST objects that are too small.
2424
// so, this plugin only convert large objects by default.
2525
const { minJSONStringSize } = state.opts
26-
const threshold =
27-
minJSONStringSize !== undefined ? minJSONStringSize : DEFAULT_THRESHOLD
26+
const threshold = minJSONStringSize ?? DEFAULT_THRESHOLD
2827
if (escapedJson.length < threshold) {
2928
return
3029
}

0 commit comments

Comments
 (0)