Skip to content

Commit

Permalink
Transpile U+2028 and U+2029 (json-superset)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianheine committed Oct 16, 2018
1 parent 59d1127 commit 08be12b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/program/types/Literal.js
Expand Up @@ -2,6 +2,8 @@ import Node from '../Node.js';
import CompileError from '../../utils/CompileError.js';
import rewritePattern from 'regexpu-core';

const nonAsciiLsOrPs = /[\u2028-\u2029]/g;

export default class Literal extends Node {
initialise() {
if (typeof this.value === 'string') {
Expand Down Expand Up @@ -37,6 +39,15 @@ export default class Literal extends Node {
}
);
}
} else if (typeof this.value === "string" && this.value.match(nonAsciiLsOrPs)) {
code.overwrite(
this.start,
this.end,
this.raw.replace(nonAsciiLsOrPs, m => m == '\u2028' ? '\\u2028' : '\\u2029'),
{
contentOnly: true
}
);
}
}
}
12 changes: 12 additions & 0 deletions test/samples/json-superset.js
@@ -0,0 +1,12 @@
module.exports = [
{
description: 'transpiles U+2028 LINE SEPARATOR',
input: `const x = "a\u2028b\u1010"`,
output: `var x = "a\\u2028b\u1010"`
},
{
description: 'transpiles U+2029 PARAGRAPH SEPARATOR',
input: `const x = "a\u2029b\u1010"`,
output: `var x = "a\\u2029b\u1010"`
}
]

0 comments on commit 08be12b

Please sign in to comment.