Skip to content

Commit

Permalink
fix: throw on unexpected pipe symbols (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke authored May 15, 2023
1 parent 2c24f44 commit 317e275
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/__tests__/namespaces.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test} from './util/helpers.mjs';
import {test, throws} from './util/helpers.mjs';

test('match tags in the postcss namespace', 'postcss|button', (t, tree) => {
t.deepEqual(tree.nodes[0].nodes[0].namespace, 'postcss');
Expand Down Expand Up @@ -76,3 +76,10 @@ test('ns alias for namespace', 'f\\oo|h1.foo', (t, tree) => {
t.deepEqual(tag.namespace, 'bar');
t.deepEqual(tag.ns, 'bar');
});

throws('lone pipe symbol', '|');
throws('lone pipe symbol with leading spaces', ' |');
throws('lone pipe symbol with trailing spaces', '| ');
throws('lone pipe symbol with surrounding spaces', ' | ');
throws('trailing pipe symbol with a namespace', 'foo| ');
throws('trailing pipe symbol with any namespace', '*| ');
6 changes: 6 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@ export default class Parser {
return this.error(`Unexpected '${this.content()}'. Escaping special characters with \\ may help.`, this.currToken[TOKEN.START_POS]);
}

unexpectedPipe () {
return this.error(`Unexpected '|'.`, this.currToken[TOKEN.START_POS]);
}

namespace () {
const before = this.prevToken && this.content(this.prevToken) || true;
if (this.nextToken[TOKEN.TYPE] === tokens.word) {
Expand All @@ -655,6 +659,8 @@ export default class Parser {
this.position ++;
return this.universal(before);
}

this.unexpectedPipe();
}

nesting () {
Expand Down

0 comments on commit 317e275

Please sign in to comment.