Subsume json (#7985)

* Add Subsume JSON transform

https://github.com/tc39/proposal-json-superset is at stage 3.

This allows U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR to appear unescaped inside strings and directives.

* Move to Stage 3

* Break diretive parsing

* Update README

* Handle multi-escape sequences

* Remove babylon files after rename
This commit is contained in:
Justin Ridgewell
2018-05-19 15:32:05 -04:00
committed by GitHub
parent 51eef099b3
commit 0879a6d608
34 changed files with 809 additions and 3 deletions

View File

@@ -1069,6 +1069,7 @@ export default class Tokenizer extends LocationParser {
readString(quote: number): void {
let out = "",
chunkStart = ++this.state.pos;
const hasJsonStrings = this.hasPlugin("jsonStrings");
for (;;) {
if (this.state.pos >= this.input.length) {
this.raise(this.state.start, "Unterminated string constant");
@@ -1080,10 +1081,14 @@ export default class Tokenizer extends LocationParser {
// $FlowFixMe
out += this.readEscapedChar(false);
chunkStart = this.state.pos;
} else if (
hasJsonStrings &&
(ch === charCodes.lineSeparator || ch === charCodes.paragraphSeparator)
) {
++this.state.pos;
} else if (isNewLine(ch)) {
this.raise(this.state.start, "Unterminated string constant");
} else {
if (isNewLine(ch)) {
this.raise(this.state.start, "Unterminated string constant");
}
++this.state.pos;
}
}

View File

@@ -0,0 +1,2 @@
"beforeafter";
// ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')

View File

@@ -0,0 +1,105 @@
{
"type": "File",
"start": 0,
"end": 98,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 82
}
},
"program": {
"type": "Program",
"start": 0,
"end": 98,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 82
}
},
"sourceType": "script",
"body": [],
"directives": [
{
"type": "Directive",
"start": 0,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 15
}
},
"value": {
"type": "DirectiveLiteral",
"start": 0,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 14
}
},
"value": "beforeafter",
"extra": {
"raw": "\"beforeafter\"",
"rawValue": "beforeafter"
}
},
"trailingComments": [
{
"type": "CommentLine",
"value": " ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')",
"start": 16,
"end": 98,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 82
}
}
}
]
}
]
},
"comments": [
{
"type": "CommentLine",
"value": " ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')",
"start": 16,
"end": 98,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 82
}
}
}
]
}

View File

@@ -0,0 +1,2 @@
"beforeafter";
// ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')

View File

@@ -0,0 +1,105 @@
{
"type": "File",
"start": 0,
"end": 103,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 87
}
},
"program": {
"type": "Program",
"start": 0,
"end": 103,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 87
}
},
"sourceType": "script",
"body": [],
"directives": [
{
"type": "Directive",
"start": 0,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 15
}
},
"value": {
"type": "DirectiveLiteral",
"start": 0,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 14
}
},
"value": "beforeafter",
"extra": {
"raw": "\"beforeafter\"",
"rawValue": "beforeafter"
}
},
"trailingComments": [
{
"type": "CommentLine",
"value": " ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')",
"start": 16,
"end": 103,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 87
}
}
}
]
}
]
},
"comments": [
{
"type": "CommentLine",
"value": " ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')",
"start": 16,
"end": 103,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 87
}
}
}
]
}

View File

@@ -0,0 +1,3 @@
{
"plugins": ["jsonStrings"]
}

View File

@@ -0,0 +1,2 @@
("beforeafter");
// ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')

View File

@@ -0,0 +1,107 @@
{
"type": "File",
"start": 0,
"end": 101,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 83
}
},
"program": {
"type": "Program",
"start": 0,
"end": 101,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 83
}
},
"sourceType": "script",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
},
"expression": {
"type": "StringLiteral",
"start": 1,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 15
}
},
"extra": {
"rawValue": "beforeafter",
"raw": "\"beforeafter\"",
"parenthesized": true,
"parenStart": 0
},
"value": "beforeafter"
},
"trailingComments": [
{
"type": "CommentLine",
"value": " ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')",
"start": 18,
"end": 101,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 83
}
}
}
]
}
],
"directives": []
},
"comments": [
{
"type": "CommentLine",
"value": " ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')",
"start": 18,
"end": 101,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 83
}
}
}
]
}

View File

@@ -0,0 +1,2 @@
("beforeafter");
// ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')

View File

@@ -0,0 +1,107 @@
{
"type": "File",
"start": 0,
"end": 106,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 88
}
},
"program": {
"type": "Program",
"start": 0,
"end": 106,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 88
}
},
"sourceType": "script",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
},
"expression": {
"type": "StringLiteral",
"start": 1,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 15
}
},
"extra": {
"rawValue": "beforeafter",
"raw": "\"beforeafter\"",
"parenthesized": true,
"parenStart": 0
},
"value": "beforeafter"
},
"trailingComments": [
{
"type": "CommentLine",
"value": " ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')",
"start": 18,
"end": 106,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 88
}
}
}
]
}
],
"directives": []
},
"comments": [
{
"type": "CommentLine",
"value": " ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')",
"start": 18,
"end": 106,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 88
}
}
}
]
}