From 765d5122c38924759a63151de395873705a7a6b2 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 14 May 2019 17:17:49 -0600 Subject: [PATCH] Allow escaped " literals in the SyntaxScopeMap In order to pass a quote literal to the postcss-selector-parser, it needs to be escaped. However, this escaping is not removed by the parser in the yielded value token, so in this commit I replace any escaped quote literals with unescaped quotes after we trim the outer quotes off of the string. --- spec/syntax-scope-map-spec.js | 4 +++- src/syntax-scope-map.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/syntax-scope-map-spec.js b/spec/syntax-scope-map-spec.js index ec52c24b6..4b30ef934 100644 --- a/spec/syntax-scope-map-spec.js +++ b/spec/syntax-scope-map-spec.js @@ -49,13 +49,15 @@ describe('SyntaxScopeMap', () => { const map = new SyntaxScopeMap({ '"b"': 'w', 'a > "b"': 'x', - 'a > "b":nth-child(1)': 'y' + 'a > "b":nth-child(1)': 'y', + '"\\""': 'z' }) expect(map.get(['b'], [0], true)).toBe(undefined) expect(map.get(['b'], [0], false)).toBe('w') expect(map.get(['a', 'b'], [0, 0], false)).toBe('x') expect(map.get(['a', 'b'], [0, 1], false)).toBe('y') + expect(map.get(['a', '"'], [0, 1], false)).toBe('z') }) it('supports the wildcard selector', () => { diff --git a/src/syntax-scope-map.js b/src/syntax-scope-map.js index 90e4cd141..39b127079 100644 --- a/src/syntax-scope-map.js +++ b/src/syntax-scope-map.js @@ -36,7 +36,7 @@ class SyntaxScopeMap { case 'string': if (!currentTable) currentTable = this.anonymousScopeTable - const value = termNode.value.slice(1, -1) + const value = termNode.value.slice(1, -1).replace(/\\"/g, '"') if (!currentTable[value]) currentTable[value] = {} currentTable = currentTable[value] if (currentIndexValue != null) {