From 676f7ea363159ea87bcb26364abe497a71291c21 Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Thu, 3 Jan 2019 16:20:36 +0200 Subject: [PATCH] preserve raw string literals in the native ast; fixes #32 Signed-off-by: Denys Smirnov --- driver/normalizer/normalizer.go | 69 ++++++++++- driver/normalizer/strconv.go | 109 ++++++++++++++++++ fixtures/call-expression.js.sem.uast | 2 +- fixtures/call-expression.js.uast | 2 +- fixtures/export-declaration.js.uast | 2 +- fixtures/ext_typedecl.js.uast | 6 +- fixtures/flow-annotations.js.uast | 2 +- fixtures/hello.js.sem.uast | 2 +- fixtures/hello.js.uast | 2 +- fixtures/import-declaration.js.uast | 18 +-- fixtures/issue24.js.uast | 2 +- fixtures/jsxelems.js.sem.uast | 6 +- fixtures/jsxelems.js.uast | 10 +- fixtures/member-expression.js.sem.uast | 2 +- fixtures/member-expression.js.uast | 2 +- fixtures/regexp-literal.js.sem.uast | 2 +- fixtures/regexp-literal.js.uast | 2 +- fixtures/string-literal.js | 1 + fixtures/string-literal.js.native | 76 +++++++++++- fixtures/string-literal.js.sem.uast | 75 +++++++++++- fixtures/string-literal.js.uast | 76 +++++++++++- fixtures/throw-statement.js.sem.uast | 2 +- fixtures/throw-statement.js.uast | 2 +- fixtures/u2_class_field.js.sem.uast | 14 +-- fixtures/u2_class_field.js.uast | 14 +-- fixtures/u2_class_method.js.sem.uast | 4 +- fixtures/u2_class_method.js.uast | 4 +- fixtures/u2_import_path.js.sem.uast | 4 +- fixtures/u2_import_path.js.uast | 4 +- fixtures/u2_import_simple.js.sem.uast | 2 +- fixtures/u2_import_simple.js.uast | 2 +- .../u2_import_specific_default.js.sem.uast | 2 +- fixtures/u2_import_specific_default.js.uast | 2 +- fixtures/u2_import_subsymbol.js.sem.uast | 4 +- fixtures/u2_import_subsymbol.js.uast | 4 +- .../u2_import_subsymbol_alias.js.sem.uast | 4 +- fixtures/u2_import_subsymbol_alias.js.uast | 4 +- ...2_import_subsymbols_namespaced.js.sem.uast | 2 +- .../u2_import_subsymbols_namespaced.js.uast | 4 +- fixtures/unary-expression.js.sem.uast | 2 +- fixtures/unary-expression.js.uast | 2 +- 41 files changed, 464 insertions(+), 86 deletions(-) create mode 100644 driver/normalizer/strconv.go diff --git a/driver/normalizer/normalizer.go b/driver/normalizer/normalizer.go index 0d435c5..76661ce 100644 --- a/driver/normalizer/normalizer.go +++ b/driver/normalizer/normalizer.go @@ -1,7 +1,10 @@ package normalizer import ( + "strings" + "gopkg.in/bblfsh/sdk.v2/uast" + "gopkg.in/bblfsh/sdk.v2/uast/nodes" . "gopkg.in/bblfsh/sdk.v2/uast/transformer" ) @@ -29,6 +32,22 @@ var Preprocessors = []Mapping{ Part("_", Obj{"loc": AnyNode(nil)}), Part("_", Obj{}), ), + // preserve raw string literal + Map( + Part("_", Obj{ + uast.KeyType: String("StringLiteral"), + "value": AnyNode(nil), + "extra": Obj{ + "raw": Var("raw"), + "rawValue": AnyNode(nil), + }, + }), + Part("_", Obj{ + uast.KeyType: String("StringLiteral"), + "value": Var("raw"), + }), + ), + // drop extra info for other nodes (it duplicates other node fields) Map( Part("_", Obj{"extra": AnyNode(nil)}), Part("_", Obj{}), @@ -47,7 +66,16 @@ var Normalizers = []Mapping{ )), MapSemantic("StringLiteral", uast.String{}, MapObj( Obj{ - "value": Var("val"), + "value": singleQuote{Var("val")}, + }, + Obj{ + "Value": Var("val"), + "Format": String("single"), + }, + )), + MapSemantic("StringLiteral", uast.String{}, MapObj( + Obj{ + "value": Quote(Var("val")), }, Obj{ "Value": Var("val"), @@ -243,3 +271,42 @@ var Normalizers = []Mapping{ }, )), } + +type singleQuote struct { + op Op +} + +func (op singleQuote) Kinds() nodes.Kind { + return nodes.KindString +} + +func (op singleQuote) Check(st *State, n nodes.Node) (bool, error) { + sn, ok := n.(nodes.String) + if !ok { + return false, nil + } + s := string(sn) + if !strings.HasPrefix(s, `'`) || !strings.HasSuffix(s, `'`) { + return false, nil + } + s = s[1 : len(s)-1] + s, err := unquoteSingle(s) + if err != nil { + return false, err + } + return op.op.Check(st, nodes.String(s)) +} + +func (op singleQuote) Construct(st *State, n nodes.Node) (nodes.Node, error) { + n, err := op.op.Construct(st, n) + if err != nil { + return nil, err + } + sn, ok := n.(nodes.String) + if !ok { + return nil, ErrUnexpectedType.New(nodes.String(""), n) + } + s := string(sn) + s = quoteSingle(s) + return nodes.String(s), nil +} diff --git a/driver/normalizer/strconv.go b/driver/normalizer/strconv.go new file mode 100644 index 0000000..6b9b161 --- /dev/null +++ b/driver/normalizer/strconv.go @@ -0,0 +1,109 @@ +package normalizer + +import ( + "strconv" + "unicode/utf8" +) + +// Functions below are copied from strconv.Unquote and strconv.Quote. +// Original functions are unable to escape/unescape values containing +// multiple characters since in Go single quotes represent a rune literal + +// unquoteSingle is the same as strconv.Unquote, but uses ' as a quote. +func unquoteSingle(s string) (string, error) { + var runeTmp [utf8.UTFMax]byte + buf := make([]byte, 0, 3*len(s)/2) + for len(s) > 0 { + c, multibyte, ss, err := strconv.UnquoteChar(s, '\'') + if err != nil { + return "", err + } + s = ss + if c < utf8.RuneSelf || !multibyte { + buf = append(buf, byte(c)) + } else { + n := utf8.EncodeRune(runeTmp[:], c) + buf = append(buf, runeTmp[:n]...) + } + } + return string(buf), nil +} + +const lowerhex = "0123456789abcdef" + +// quoteSingle is the same as strconv.Quote, but uses ' as a quote. +func quoteSingle(s string) string { + const ( + quote = '\'' + ) + + buf := make([]byte, 0, 3*len(s)/2) + buf = append(buf, quote) + for width := 0; len(s) > 0; s = s[width:] { + r := rune(s[0]) + width = 1 + if r >= utf8.RuneSelf { + r, width = utf8.DecodeRuneInString(s) + } + if width == 1 && r == utf8.RuneError { + buf = append(buf, `\x`...) + buf = append(buf, lowerhex[s[0]>>4]) + buf = append(buf, lowerhex[s[0]&0xF]) + continue + } + buf = appendEscapedRune(buf, r, quote) + } + buf = append(buf, quote) + return string(buf) +} + +func appendEscapedRune(buf []byte, r rune, quote byte) []byte { + var runeTmp [utf8.UTFMax]byte + if r == rune(quote) || r == '\\' { // always backslashed + buf = append(buf, '\\') + buf = append(buf, byte(r)) + return buf + } + if strconv.IsPrint(r) { + n := utf8.EncodeRune(runeTmp[:], r) + buf = append(buf, runeTmp[:n]...) + return buf + } + switch r { + case '\a': + buf = append(buf, `\a`...) + case '\b': + buf = append(buf, `\b`...) + case '\f': + buf = append(buf, `\f`...) + case '\n': + buf = append(buf, `\n`...) + case '\r': + buf = append(buf, `\r`...) + case '\t': + buf = append(buf, `\t`...) + case '\v': + buf = append(buf, `\v`...) + default: + switch { + case r < ' ': + buf = append(buf, `\x`...) + buf = append(buf, lowerhex[byte(r)>>4]) + buf = append(buf, lowerhex[byte(r)&0xF]) + case r > utf8.MaxRune: + r = 0xFFFD + fallthrough + case r < 0x10000: + buf = append(buf, `\u`...) + for s := 12; s >= 0; s -= 4 { + buf = append(buf, lowerhex[r>>uint(s)&0xF]) + } + default: + buf = append(buf, `\U`...) + for s := 28; s >= 0; s -= 4 { + buf = append(buf, lowerhex[r>>uint(s)&0xF]) + } + } + } + return buf +} diff --git a/fixtures/call-expression.js.sem.uast b/fixtures/call-expression.js.sem.uast index 6120801..d05fb04 100644 --- a/fixtures/call-expression.js.sem.uast +++ b/fixtures/call-expression.js.sem.uast @@ -425,7 +425,7 @@ col: 10, }, }, - Format: "", + Format: "single", Value: "", }, ], diff --git a/fixtures/call-expression.js.uast b/fixtures/call-expression.js.uast index bcd0c22..681ce2a 100644 --- a/fixtures/call-expression.js.uast +++ b/fixtures/call-expression.js.uast @@ -414,7 +414,7 @@ }, arguments: [ { '@type': "StringLiteral", - '@token': "", + '@token': "''", '@role': [Argument, Call, Expression, Literal, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/export-declaration.js.uast b/fixtures/export-declaration.js.uast index c7d5512..c710507 100644 --- a/fixtures/export-declaration.js.uast +++ b/fixtures/export-declaration.js.uast @@ -144,7 +144,7 @@ }, exportKind: "value", source: { '@type': "StringLiteral", - '@token': "mod", + '@token': "\"mod\"", '@role': [Expression, Literal, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/ext_typedecl.js.uast b/fixtures/ext_typedecl.js.uast index d07d613..892d7b8 100644 --- a/fixtures/ext_typedecl.js.uast +++ b/fixtures/ext_typedecl.js.uast @@ -754,7 +754,7 @@ }, }, expression: { '@type': "StringLiteral", - '@token': "babel", + '@token': "\"babel\"", '@role': [Expression, Literal, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -905,7 +905,7 @@ '@role': [Binary, Expression, Identical, Operator, Relational], }, right: { '@type': "StringLiteral", - '@token': "undefined", + '@token': "\"undefined\"", '@role': [Binary, Expression, Literal, Right, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -1185,7 +1185,7 @@ '@role': [Binary, Expression, Identical, Not, Operator, Relational], }, right: { '@type': "StringLiteral", - '@token': "object", + '@token': "\"object\"", '@role': [Binary, Expression, Literal, Right, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/flow-annotations.js.uast b/fixtures/flow-annotations.js.uast index 6ca7d56..d11f141 100644 --- a/fixtures/flow-annotations.js.uast +++ b/fixtures/flow-annotations.js.uast @@ -1634,7 +1634,7 @@ }, }, value: { '@type': "StringLiteral", - '@token': "foo", + '@token': "\"foo\"", '@role': [Expression, Initialization, Literal, String, Value], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/hello.js.sem.uast b/fixtures/hello.js.sem.uast index 7f450d0..5a962c1 100644 --- a/fixtures/hello.js.sem.uast +++ b/fixtures/hello.js.sem.uast @@ -71,7 +71,7 @@ col: 26, }, }, - Format: "", + Format: "single", Value: "Hello World", }, ], diff --git a/fixtures/hello.js.uast b/fixtures/hello.js.uast index cb3e897..96f116f 100644 --- a/fixtures/hello.js.uast +++ b/fixtures/hello.js.uast @@ -58,7 +58,7 @@ }, arguments: [ { '@type': "StringLiteral", - '@token': "Hello World", + '@token': "'Hello World'", '@role': [Argument, Call, Expression, Literal, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/import-declaration.js.uast b/fixtures/import-declaration.js.uast index f40c454..aefceb0 100644 --- a/fixtures/import-declaration.js.uast +++ b/fixtures/import-declaration.js.uast @@ -44,7 +44,7 @@ }, importKind: "value", source: { '@type': "StringLiteral", - '@token': "module-name", + '@token': "\"module-name\"", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -109,7 +109,7 @@ }, importKind: "value", source: { '@type': "StringLiteral", - '@token': "module-name", + '@token': "\"module-name\"", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -174,7 +174,7 @@ }, importKind: "value", source: { '@type': "StringLiteral", - '@token': "module-name", + '@token': "\"module-name\"", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -256,7 +256,7 @@ }, importKind: "value", source: { '@type': "StringLiteral", - '@token': "module-name", + '@token': "\"module-name\"", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -338,7 +338,7 @@ }, importKind: "value", source: { '@type': "StringLiteral", - '@token': "module-name", + '@token': "\"module-name\"", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -468,7 +468,7 @@ }, importKind: "value", source: { '@type': "StringLiteral", - '@token': "module-name", + '@token': "\"module-name\"", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -598,7 +598,7 @@ }, importKind: "value", source: { '@type': "StringLiteral", - '@token': "module-name", + '@token': "\"module-name\"", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -711,7 +711,7 @@ }, importKind: "value", source: { '@type': "StringLiteral", - '@token': "module-name", + '@token': "\"module-name\"", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -806,7 +806,7 @@ }, }, source: { '@type': "StringLiteral", - '@token': "module-name", + '@token': "\"module-name\"", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/issue24.js.uast b/fixtures/issue24.js.uast index 8c6068b..10f497a 100644 --- a/fixtures/issue24.js.uast +++ b/fixtures/issue24.js.uast @@ -127,7 +127,7 @@ }, ], source: { '@type': "StringLiteral", - '@token': "./file/file", + '@token': "\"./file/file\"", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/jsxelems.js.sem.uast b/fixtures/jsxelems.js.sem.uast index a0f7731..8af02fc 100644 --- a/fixtures/jsxelems.js.sem.uast +++ b/fixtures/jsxelems.js.sem.uast @@ -86,7 +86,7 @@ col: 22, }, }, - Format: "", + Format: "single", Value: "quotes", }, }, @@ -151,7 +151,7 @@ col: 25, }, }, - Format: "", + Format: "single", Value: "double", }, }, @@ -216,7 +216,7 @@ col: 37, }, }, - Format: "", + Format: "single", Value: "!", }, }, diff --git a/fixtures/jsxelems.js.uast b/fixtures/jsxelems.js.uast index c88f753..126754f 100644 --- a/fixtures/jsxelems.js.uast +++ b/fixtures/jsxelems.js.uast @@ -74,7 +74,7 @@ }, }, init: { '@type': "StringLiteral", - '@token': "quotes", + '@token': "'quotes'", '@role': [Expression, Initialization, Literal, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -139,7 +139,7 @@ }, }, init: { '@type': "StringLiteral", - '@token': "double", + '@token': "'double'", '@role': [Expression, Initialization, Literal, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -204,7 +204,7 @@ }, }, init: { '@type': "StringLiteral", - '@token': "!", + '@token': "'!'", '@role': [Expression, Initialization, Literal, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -373,7 +373,7 @@ name: "multiple", }, value: { '@type': "StringLiteral", - '@token': "attributes", + '@token': "\"attributes\"", '@role': [Expression, Literal, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -420,7 +420,7 @@ name: "attribute", }, value: { '@type': "StringLiteral", - '@token': "If parent is JSX keep double quote", + '@token': "\"If parent is JSX keep double quote\"", '@role': [Expression, Literal, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/member-expression.js.sem.uast b/fixtures/member-expression.js.sem.uast index f04d015..7510961 100644 --- a/fixtures/member-expression.js.sem.uast +++ b/fixtures/member-expression.js.sem.uast @@ -209,7 +209,7 @@ col: 14, }, }, - Format: "", + Format: "single", Value: "b", }, }, diff --git a/fixtures/member-expression.js.uast b/fixtures/member-expression.js.uast index 66c12ab..bc6eabc 100644 --- a/fixtures/member-expression.js.uast +++ b/fixtures/member-expression.js.uast @@ -202,7 +202,7 @@ }, }, property: { '@type': "StringLiteral", - '@token': "b", + '@token': "'b'", '@role': [Expression, Literal, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/regexp-literal.js.sem.uast b/fixtures/regexp-literal.js.sem.uast index 069c331..f27c831 100644 --- a/fixtures/regexp-literal.js.sem.uast +++ b/fixtures/regexp-literal.js.sem.uast @@ -120,7 +120,7 @@ col: 22, }, }, - Format: "", + Format: "single", Value: "x", }, ], diff --git a/fixtures/regexp-literal.js.uast b/fixtures/regexp-literal.js.uast index be21577..7cbb9bf 100644 --- a/fixtures/regexp-literal.js.uast +++ b/fixtures/regexp-literal.js.uast @@ -107,7 +107,7 @@ flags: "g", }, { '@type': "StringLiteral", - '@token': "x", + '@token': "'x'", '@role': [Argument, Call, Expression, Literal, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/string-literal.js b/fixtures/string-literal.js index 3e04d37..ed039fd 100644 --- a/fixtures/string-literal.js +++ b/fixtures/string-literal.js @@ -1 +1,2 @@ a = "a" +bc = "b\nc" diff --git a/fixtures/string-literal.js.native b/fixtures/string-literal.js.native index 6d7d4d4..81eba58 100644 --- a/fixtures/string-literal.js.native +++ b/fixtures/string-literal.js.native @@ -1,10 +1,10 @@ { comments: [], - end: 8, + end: 20, loc: { end: { column: 0, - line: 2, + line: 3, }, start: { column: 0, @@ -81,13 +81,81 @@ start: 0, type: "ExpressionStatement", }, + { + end: 19, + expression: { + end: 19, + left: { + end: 10, + loc: { + end: { + column: 2, + line: 2, + }, + identifierName: "bc", + start: { + column: 0, + line: 2, + }, + }, + name: "bc", + start: 8, + type: "Identifier", + }, + loc: { + end: { + column: 11, + line: 2, + }, + start: { + column: 0, + line: 2, + }, + }, + operator: "=", + right: { + end: 19, + extra: { + raw: "\"b\\nc\"", + rawValue: "b\nc", + }, + loc: { + end: { + column: 11, + line: 2, + }, + start: { + column: 5, + line: 2, + }, + }, + start: 13, + type: "StringLiteral", + value: "b\nc", + }, + start: 8, + type: "AssignmentExpression", + }, + loc: { + end: { + column: 11, + line: 2, + }, + start: { + column: 0, + line: 2, + }, + }, + start: 8, + type: "ExpressionStatement", + }, ], directives: [], - end: 8, + end: 20, loc: { end: { column: 0, - line: 2, + line: 3, }, start: { column: 0, diff --git a/fixtures/string-literal.js.sem.uast b/fixtures/string-literal.js.sem.uast index 96d2515..5503b55 100644 --- a/fixtures/string-literal.js.sem.uast +++ b/fixtures/string-literal.js.sem.uast @@ -7,8 +7,8 @@ col: 1, }, end: { '@type': "uast:Position", - offset: 8, - line: 2, + offset: 20, + line: 3, col: 1, }, }, @@ -22,8 +22,8 @@ col: 1, }, end: { '@type': "uast:Position", - offset: 8, - line: 2, + offset: 20, + line: 3, col: 1, }, }, @@ -95,6 +95,73 @@ }, }, }, + { '@type': "javascript:ExpressionStatement", + '@role': [Statement], + '@pos': { '@type': "uast:Positions", + start: { '@type': "uast:Position", + offset: 8, + line: 2, + col: 1, + }, + end: { '@type': "uast:Position", + offset: 19, + line: 2, + col: 12, + }, + }, + expression: { '@type': "javascript:AssignmentExpression", + '@role': [Assignment, Binary, Expression, Operator], + '@pos': { '@type': "uast:Positions", + start: { '@type': "uast:Position", + offset: 8, + line: 2, + col: 1, + }, + end: { '@type': "uast:Position", + offset: 19, + line: 2, + col: 12, + }, + }, + left: { '@type': "uast:Identifier", + '@role': [Assignment, Binary, Left], + '@pos': { '@type': "uast:Positions", + start: { '@type': "uast:Position", + offset: 8, + line: 2, + col: 1, + }, + end: { '@type': "uast:Position", + offset: 10, + line: 2, + col: 3, + }, + }, + Name: "bc", + }, + operator: { '@type': "uast:Operator", + '@token': "=", + '@role': [Assignment, Binary, Expression, Operator], + }, + right: { '@type': "uast:String", + '@role': [Assignment, Binary, Right], + '@pos': { '@type': "uast:Positions", + start: { '@type': "uast:Position", + offset: 13, + line: 2, + col: 6, + }, + end: { '@type': "uast:Position", + offset: 19, + line: 2, + col: 12, + }, + }, + Format: "", + Value: "b\nc", + }, + }, + }, ], directives: [], sourceType: "module", diff --git a/fixtures/string-literal.js.uast b/fixtures/string-literal.js.uast index 9684575..188d6f9 100644 --- a/fixtures/string-literal.js.uast +++ b/fixtures/string-literal.js.uast @@ -7,8 +7,8 @@ col: 1, }, end: { '@type': "uast:Position", - offset: 8, - line: 2, + offset: 20, + line: 3, col: 1, }, }, @@ -22,8 +22,8 @@ col: 1, }, end: { '@type': "uast:Position", - offset: 8, - line: 2, + offset: 20, + line: 3, col: 1, }, }, @@ -77,7 +77,7 @@ '@role': [Assignment, Binary, Expression, Operator], }, right: { '@type': "StringLiteral", - '@token': "a", + '@token': "\"a\"", '@role': [Assignment, Binary, Expression, Literal, Right, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -94,6 +94,72 @@ }, }, }, + { '@type': "ExpressionStatement", + '@role': [Statement], + '@pos': { '@type': "uast:Positions", + start: { '@type': "uast:Position", + offset: 8, + line: 2, + col: 1, + }, + end: { '@type': "uast:Position", + offset: 19, + line: 2, + col: 12, + }, + }, + expression: { '@type': "AssignmentExpression", + '@role': [Assignment, Binary, Expression, Operator], + '@pos': { '@type': "uast:Positions", + start: { '@type': "uast:Position", + offset: 8, + line: 2, + col: 1, + }, + end: { '@type': "uast:Position", + offset: 19, + line: 2, + col: 12, + }, + }, + left: { '@type': "Identifier", + '@token': "bc", + '@role': [Assignment, Binary, Expression, Identifier, Left], + '@pos': { '@type': "uast:Positions", + start: { '@type': "uast:Position", + offset: 8, + line: 2, + col: 1, + }, + end: { '@type': "uast:Position", + offset: 10, + line: 2, + col: 3, + }, + }, + }, + operator: { '@type': "uast:Operator", + '@token': "=", + '@role': [Assignment, Binary, Expression, Operator], + }, + right: { '@type': "StringLiteral", + '@token': "\"b\\nc\"", + '@role': [Assignment, Binary, Expression, Literal, Right, String], + '@pos': { '@type': "uast:Positions", + start: { '@type': "uast:Position", + offset: 13, + line: 2, + col: 6, + }, + end: { '@type': "uast:Position", + offset: 19, + line: 2, + col: 12, + }, + }, + }, + }, + }, ], directives: [], sourceType: "module", diff --git a/fixtures/throw-statement.js.sem.uast b/fixtures/throw-statement.js.sem.uast index 6e2a0fa..2c3834f 100644 --- a/fixtures/throw-statement.js.sem.uast +++ b/fixtures/throw-statement.js.sem.uast @@ -55,7 +55,7 @@ col: 18, }, }, - Format: "", + Format: "single", Value: "exception", }, }, diff --git a/fixtures/throw-statement.js.uast b/fixtures/throw-statement.js.uast index 3a514b4..49a13fb 100644 --- a/fixtures/throw-statement.js.uast +++ b/fixtures/throw-statement.js.uast @@ -43,7 +43,7 @@ }, }, argument: { '@type': "StringLiteral", - '@token': "exception", + '@token': "'exception'", '@role': [Expression, Literal, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/u2_class_field.js.sem.uast b/fixtures/u2_class_field.js.sem.uast index 77b2533..8838de5 100644 --- a/fixtures/u2_class_field.js.sem.uast +++ b/fixtures/u2_class_field.js.sem.uast @@ -199,7 +199,7 @@ col: 48, }, }, - Format: "", + Format: "single", Value: "A", }, }, @@ -307,7 +307,7 @@ col: 36, }, }, - Format: "", + Format: "single", Value: "foo", }, method: false, @@ -326,7 +326,7 @@ col: 41, }, }, - Format: "", + Format: "single", Value: "A", }, }, @@ -472,7 +472,7 @@ col: 22, }, }, - Format: "", + Format: "single", Value: "foo", }, method: false, @@ -491,7 +491,7 @@ col: 27, }, }, - Format: "", + Format: "single", Value: "A", }, }, @@ -667,7 +667,7 @@ col: 19, }, }, - Format: "", + Format: "single", Value: "A", }, }, @@ -833,7 +833,7 @@ col: 23, }, }, - Format: "", + Format: "single", Value: "A", }, }, diff --git a/fixtures/u2_class_field.js.uast b/fixtures/u2_class_field.js.uast index bef896a..86b22d7 100644 --- a/fixtures/u2_class_field.js.uast +++ b/fixtures/u2_class_field.js.uast @@ -190,7 +190,7 @@ '@role': [Assignment, Binary, Expression, Operator], }, right: { '@type': "StringLiteral", - '@token': "A", + '@token': "'A'", '@role': [Assignment, Binary, Expression, Literal, Right, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -298,7 +298,7 @@ }, computed: false, key: { '@type': "StringLiteral", - '@token': "foo", + '@token': "'foo'", '@role': [Expression, Key, Literal, Map, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -316,7 +316,7 @@ method: false, shorthand: false, value: { '@type': "StringLiteral", - '@token': "A", + '@token': "'A'", '@role': [Expression, Literal, Map, String, Value], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -464,7 +464,7 @@ }, computed: false, key: { '@type': "StringLiteral", - '@token': "foo", + '@token': "'foo'", '@role': [Expression, Key, Literal, Map, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -482,7 +482,7 @@ method: false, shorthand: false, value: { '@type': "StringLiteral", - '@token': "A", + '@token': "'A'", '@role': [Expression, Literal, Map, String, Value], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -659,7 +659,7 @@ '@role': [Assignment, Binary, Expression, Operator], }, right: { '@type': "StringLiteral", - '@token': "A", + '@token': "'A'", '@role': [Assignment, Binary, Expression, Literal, Right, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -826,7 +826,7 @@ '@role': [Assignment, Binary, Expression, Operator], }, right: { '@type': "StringLiteral", - '@token': "A", + '@token': "'A'", '@role': [Assignment, Binary, Expression, Literal, Right, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/u2_class_method.js.sem.uast b/fixtures/u2_class_method.js.sem.uast index 79b78c3..2de4626 100644 --- a/fixtures/u2_class_method.js.sem.uast +++ b/fixtures/u2_class_method.js.sem.uast @@ -1164,7 +1164,7 @@ col: 41, }, }, - Format: "", + Format: "single", Value: "testfnc2", }, method: false, @@ -1347,7 +1347,7 @@ col: 27, }, }, - Format: "", + Format: "single", Value: "testfnc3", }, method: false, diff --git a/fixtures/u2_class_method.js.uast b/fixtures/u2_class_method.js.uast index f739cb0..0face3c 100644 --- a/fixtures/u2_class_method.js.uast +++ b/fixtures/u2_class_method.js.uast @@ -1134,7 +1134,7 @@ }, computed: false, key: { '@type': "StringLiteral", - '@token': "testfnc2", + '@token': "'testfnc2'", '@role': [Expression, Key, Literal, Map, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -1320,7 +1320,7 @@ }, computed: false, key: { '@type': "StringLiteral", - '@token': "testfnc3", + '@token': "'testfnc3'", '@role': [Expression, Key, Literal, Map, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/u2_import_path.js.sem.uast b/fixtures/u2_import_path.js.sem.uast index 158cd9a..25d400e 100644 --- a/fixtures/u2_import_path.js.sem.uast +++ b/fixtures/u2_import_path.js.sem.uast @@ -56,7 +56,7 @@ col: 14, }, }, - Format: "", + Format: "single", Value: "file", }, Target: ~, @@ -89,7 +89,7 @@ col: 22, }, }, - Format: "", + Format: "single", Value: "./local/file", }, Target: ~, diff --git a/fixtures/u2_import_path.js.uast b/fixtures/u2_import_path.js.uast index 26cb3a4..f9bab52 100644 --- a/fixtures/u2_import_path.js.uast +++ b/fixtures/u2_import_path.js.uast @@ -43,7 +43,7 @@ }, }, source: { '@type': "StringLiteral", - '@token': "file", + '@token': "'file'", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -75,7 +75,7 @@ }, }, source: { '@type': "StringLiteral", - '@token': "./local/file", + '@token': "'./local/file'", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/u2_import_simple.js.sem.uast b/fixtures/u2_import_simple.js.sem.uast index 2e9a69e..54b920c 100644 --- a/fixtures/u2_import_simple.js.sem.uast +++ b/fixtures/u2_import_simple.js.sem.uast @@ -56,7 +56,7 @@ col: 15, }, }, - Format: "", + Format: "single", Value: "file1", }, Target: ~, diff --git a/fixtures/u2_import_simple.js.uast b/fixtures/u2_import_simple.js.uast index 899cfce..dc326ee 100644 --- a/fixtures/u2_import_simple.js.uast +++ b/fixtures/u2_import_simple.js.uast @@ -43,7 +43,7 @@ }, }, source: { '@type': "StringLiteral", - '@token': "file1", + '@token': "'file1'", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/u2_import_specific_default.js.sem.uast b/fixtures/u2_import_specific_default.js.sem.uast index 841111b..a079662 100644 --- a/fixtures/u2_import_specific_default.js.sem.uast +++ b/fixtures/u2_import_specific_default.js.sem.uast @@ -90,7 +90,7 @@ col: 23, }, }, - Format: "", + Format: "single", Value: "file", }, Target: ~, diff --git a/fixtures/u2_import_specific_default.js.uast b/fixtures/u2_import_specific_default.js.uast index 0e4af6f..61ddec6 100644 --- a/fixtures/u2_import_specific_default.js.uast +++ b/fixtures/u2_import_specific_default.js.uast @@ -44,7 +44,7 @@ }, importKind: "value", source: { '@type': "StringLiteral", - '@token': "file", + '@token': "'file'", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/u2_import_subsymbol.js.sem.uast b/fixtures/u2_import_subsymbol.js.sem.uast index 5afbcbe..f6cd2de 100644 --- a/fixtures/u2_import_subsymbol.js.sem.uast +++ b/fixtures/u2_import_subsymbol.js.sem.uast @@ -90,7 +90,7 @@ col: 24, }, }, - Format: "", + Format: "single", Value: "file1", }, Target: ~, @@ -212,7 +212,7 @@ col: 33, }, }, - Format: "", + Format: "single", Value: "file2", }, Target: ~, diff --git a/fixtures/u2_import_subsymbol.js.uast b/fixtures/u2_import_subsymbol.js.uast index 5ccbf99..d317d3e 100644 --- a/fixtures/u2_import_subsymbol.js.uast +++ b/fixtures/u2_import_subsymbol.js.uast @@ -44,7 +44,7 @@ }, importKind: "value", source: { '@type': "StringLiteral", - '@token': "file1", + '@token': "'file1'", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -109,7 +109,7 @@ }, importKind: "value", source: { '@type': "StringLiteral", - '@token': "file2", + '@token': "'file2'", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/u2_import_subsymbol_alias.js.sem.uast b/fixtures/u2_import_subsymbol_alias.js.sem.uast index 57631b6..ffb4a81 100644 --- a/fixtures/u2_import_subsymbol_alias.js.sem.uast +++ b/fixtures/u2_import_subsymbol_alias.js.sem.uast @@ -101,7 +101,7 @@ col: 38, }, }, - Format: "", + Format: "single", Value: "file", }, Target: ~, @@ -223,7 +223,7 @@ col: 56, }, }, - Format: "", + Format: "single", Value: "file", }, Target: ~, diff --git a/fixtures/u2_import_subsymbol_alias.js.uast b/fixtures/u2_import_subsymbol_alias.js.uast index 8e3133b..381472d 100644 --- a/fixtures/u2_import_subsymbol_alias.js.uast +++ b/fixtures/u2_import_subsymbol_alias.js.uast @@ -44,7 +44,7 @@ }, importKind: "value", source: { '@type': "StringLiteral", - '@token': "file", + '@token': "'file'", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -126,7 +126,7 @@ }, importKind: "value", source: { '@type': "StringLiteral", - '@token': "file", + '@token': "'file'", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/u2_import_subsymbols_namespaced.js.sem.uast b/fixtures/u2_import_subsymbols_namespaced.js.sem.uast index 60343e5..6c131f9 100644 --- a/fixtures/u2_import_subsymbols_namespaced.js.sem.uast +++ b/fixtures/u2_import_subsymbols_namespaced.js.sem.uast @@ -84,7 +84,7 @@ col: 34, }, }, - Format: "", + Format: "single", Value: "file", }, }, diff --git a/fixtures/u2_import_subsymbols_namespaced.js.uast b/fixtures/u2_import_subsymbols_namespaced.js.uast index 32f4ced..0460282 100644 --- a/fixtures/u2_import_subsymbols_namespaced.js.uast +++ b/fixtures/u2_import_subsymbols_namespaced.js.uast @@ -44,7 +44,7 @@ }, importKind: "value", source: { '@type': "StringLiteral", - '@token': "file", + '@token': "'file'", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", @@ -109,7 +109,7 @@ }, importKind: "type", source: { '@type': "StringLiteral", - '@token': "file", + '@token': "\"file\"", '@role': [Expression, Import, Literal, Pathname, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position", diff --git a/fixtures/unary-expression.js.sem.uast b/fixtures/unary-expression.js.sem.uast index 2fa1d3c..ea9ba87 100644 --- a/fixtures/unary-expression.js.sem.uast +++ b/fixtures/unary-expression.js.sem.uast @@ -486,7 +486,7 @@ col: 13, }, }, - Format: "", + Format: "single", Value: "x", }, }, diff --git a/fixtures/unary-expression.js.uast b/fixtures/unary-expression.js.uast index ab395eb..2f66e14 100644 --- a/fixtures/unary-expression.js.uast +++ b/fixtures/unary-expression.js.uast @@ -477,7 +477,7 @@ }, }, property: { '@type': "StringLiteral", - '@token': "x", + '@token': "'x'", '@role': [Expression, Literal, String], '@pos': { '@type': "uast:Positions", start: { '@type': "uast:Position",