+7
-11
@@ -1058,17 +1058,15 @@ import { LexContext, Token, Lexer, TokenValue } from "./lexer.js"; | ||
| const valStart = eqIdx + 1; | ||
| const valText = text.slice(valStart); | ||
| const valueStart = tokPos + valStart; | ||
| // Check for array assignment: value starts with ( | ||
| if (valText.charCodeAt(0) === 0x28 /* ( */ && valText.charCodeAt(valText.length - 1) === 0x29 /* ) */) { | ||
| const inner = valText.slice(1, -1); | ||
| const arrayOffset = tokPos + valStart + 1; | ||
| const elements = this.parseArrayElements(inner, arrayOffset); | ||
| if (text.charCodeAt(valStart) === 0x28 /* ( */ && text.charCodeAt(text.length - 1) === 0x29 /* ) */) { | ||
| const elements = this.parseArrayElements(valueStart + 1, tokEnd - 1); | ||
| result.array = elements; | ||
| } | ||
| else { | ||
| result.value = new WordImpl(valText, tokPos + valStart, tokEnd, this.source); | ||
| result.value = new WordImpl(text.slice(valStart), valueStart, tokEnd, this.source); | ||
| } | ||
| return result; | ||
| } | ||
| parseArrayElements(inner, offset = 0) { | ||
| const subTok = new Lexer(inner); | ||
| parseArrayElements(start, end) { | ||
| const subTok = new Lexer(this.source, start, end); | ||
| const elements = []; | ||
@@ -1082,5 +1080,3 @@ while (subTok.peek(LexContext.Normal).token !== Token.EOF) { | ||
| if (t.token === Token.Word || t.token === Token.Assignment) { | ||
| const pos = t.pos + offset; | ||
| const end = t.end + offset; | ||
| elements.push(new WordImpl(this.source.slice(pos, end), pos, end, this.source)); | ||
| elements.push(new WordImpl(this.source.slice(t.pos, t.end), t.pos, t.end, this.source)); | ||
| } | ||
@@ -1087,0 +1083,0 @@ } |
+23
-1
@@ -7,2 +7,24 @@ function dequoteValue(parts) { | ||
| } | ||
| function unescapeBareValue(text) { | ||
| const first = text.indexOf("\\"); | ||
| if (first === -1) | ||
| return text; | ||
| let s = ""; | ||
| let start = 0; | ||
| for (let i = first; i < text.length; i++) { | ||
| if (text.charCodeAt(i) !== 92) | ||
| continue; | ||
| s += text.slice(start, i); | ||
| i++; | ||
| if (i >= text.length) { | ||
| s += "\\"; | ||
| start = i; | ||
| break; | ||
| } | ||
| if (text.charCodeAt(i) !== 10) | ||
| s += text[i]; | ||
| start = i + 1; | ||
| } | ||
| return s + text.slice(start); | ||
| } | ||
| export class WordImpl { | ||
@@ -30,3 +52,3 @@ static _resolveWord; | ||
| if (!parts) { | ||
| this.#value = this.text; | ||
| this.#value = unescapeBareValue(this.text); | ||
| } | ||
@@ -33,0 +55,0 @@ else { |
+1
-1
| { | ||
| "name": "unbash", | ||
| "version": "4.0.1", | ||
| "version": "4.0.2", | ||
| "description": "Fast 0-deps bash parser written in TypeScript", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
181266
0.22%5063
0.36%