Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Commit

Permalink
Template names can have underscores
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Hadley committed May 26, 2017
1 parent 80b76b6 commit c2a183c
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
60 changes: 60 additions & 0 deletions src/__tests__/__snapshots__/parser.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3074,3 +3074,63 @@ Some more docs
"type": "Program",
}
`;

exports[`Soy Parser should parse template name with an underscore 1`] = `
Object {
"body": Array [
Object {
"attributes": Array [],
"body": Array [],
"doc": Object {
"about": "",
"mark": Object {
"end": Object {
"column": 1,
"line": 6,
"offset": 37,
},
"start": Object {
"column": 1,
"line": 3,
"offset": 26,
},
},
"params": Array [],
"type": "SoyDoc",
},
"id": Object {
"name": "with_underscore",
"namespace": null,
},
"mark": Object {
"end": Object {
"column": 12,
"line": 7,
"offset": 76,
},
"start": Object {
"column": 1,
"line": 3,
"offset": 26,
},
},
"params": Array [],
"type": "Template",
},
],
"mark": Object {
"end": Object {
"column": 1,
"line": 8,
"offset": 77,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"namespace": "TemplateName",
"type": "Program",
}
`;
6 changes: 6 additions & 0 deletions src/__tests__/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,10 @@ describe('Soy Parser', () => {

expect(soyParser(input)).toMatchSnapshot();
});

test('should parse template name with an underscore', () => {
const input = getFixture('TemplateName.soy');

expect(soyParser(input)).toMatchSnapshot();
});
});
4 changes: 2 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const squote = P.string('\'');
const underscore = P.string('_');

const attributeName = joined(P.letter, P.string('-'));
const functionName = joined(P.letter, underscore);
const functionName = joined(P.letter, underscore, P.digit);
const html = P.noneOf('{}').many().desc("Html Char");
const identifierName = joined(P.letter, P.digit, underscore);
const namespace = joined(P.letter, P.digit, P.string('.'));
const namespace = joined(P.letter, P.digit, P.string('.'), underscore);

const templateName = namespace.map(parseTemplateName);

Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/TemplateName.soy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{namespace TemplateName}

/**
*
*/
{template .with_underscore}
{/template}

0 comments on commit c2a183c

Please sign in to comment.