Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename parser/AST from 'melody' into 'twig' #39

Merged
merged 3 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"scripts": {
"lint": "DEBUG=eslint:cli-engine eslint .",
"prettier": "prettier --plugin=./src/index.js --parser=melody",
"prettier": "prettier --plugin=./src/index.js --parser=twig",
"test": "vitest --run"
},
"dependencies": {
Expand Down
19 changes: 6 additions & 13 deletions src/index.js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to include the language features but specifically for Twig most of the language information can be found here: https://github.com/github-linguist/linguist/blob/39fd5e93de98de3434cb3e857c5b1972c418f8c5/lib/linguist/languages.yml#L7342
The available options can be found here: https://github.com/prettier/prettier/blob/92b8c1cda33960d6ee84c3e17eab0113b7f0f330/src/index.d.ts#L651

I am not sure what functionality you would be gaining or losing by adding or removing these options but seems like a good thing to include if they are available

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what this language information is used for. If no feature affected by missing this information, I will leave it as is.

Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,9 @@ import * as publicFunctions from "./util/publicFunctions.js";
*/
const languages = [
{
name: "melody",
parsers: ["melody"],
group: "Melody",
tmScope: "melody.twig",
aceMode: "html",
codemirrorMode: "clike",
codemirrorMimeType: "text/melody-twig",
extensions: [".melody.twig", ".html.twig", ".twig"],
linguistLanguageId: 0,
vscodeLanguageIds: ["twig"]
name: "twig",
parsers: ["twig"],
extensions: [".html.twig", ".twig"]
}
];

Expand All @@ -29,9 +22,9 @@ const languages = [
* @type Record<string, Parser>
*/
const parsers = {
melody: {
twig: {
parse,
astFormat: "melody",
astFormat: "twig",
hasPragma() {
return false;
},
Expand All @@ -50,7 +43,7 @@ const parsers = {
* @type Record<string, Printer>
*/
const printers = {
melody: {
twig: {
print,
printComment(commentPath) {
const comment = commentPath.getValue();
Expand Down
4 changes: 2 additions & 2 deletions tests/Comments/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`htmlComments.melody.twig - melody-verify > htmlComments.melody.twig 1`] = `
exports[`htmlComments.melody.twig - twig-verify > htmlComments.melody.twig 1`] = `
<!-- I am a comment -->
This is a paragraph

Expand Down Expand Up @@ -34,7 +34,7 @@ A third paragraph

`;

exports[`twigComments.melody.twig - melody-verify > twigComments.melody.twig 1`] = `
exports[`twigComments.melody.twig - twig-verify > twigComments.melody.twig 1`] = `
{# One #}

{# Two #}
Expand Down
2 changes: 1 addition & 1 deletion tests/Comments/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(__dirname, ["melody"]);
run_spec(__dirname, ["twig"]);
6 changes: 3 additions & 3 deletions tests/ConstantValue/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`constant-value-int.melody.twig - melody-verify > constant-value-int.melody.twig 1`] = `
exports[`constant-value-int.melody.twig - twig-verify > constant-value-int.melody.twig 1`] = `
123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123

`;

exports[`constant-value-string.melody.twig - melody-verify > constant-value-string.melody.twig 1`] = `
exports[`constant-value-string.melody.twig - twig-verify > constant-value-string.melody.twig 1`] = `
Test string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Test string

`;

exports[`special-cases.melody.twig - melody-verify > special-cases.melody.twig 1`] = `
exports[`special-cases.melody.twig - twig-verify > special-cases.melody.twig 1`] = `
{% if isRTL %}&#8206;{% endif %}

{% if searchResultFailing %}
Expand Down
2 changes: 1 addition & 1 deletion tests/ConstantValue/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(__dirname, ["melody"]);
run_spec(__dirname, ["twig"]);
10 changes: 5 additions & 5 deletions tests/ControlStructures/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`for.melody.twig - melody-verify > for.melody.twig 1`] = `
exports[`for.melody.twig - twig-verify > for.melody.twig 1`] = `
<ul>
{% for item in items %}
<li class="{{ loop.last ? 'last' : '' }}">
Expand Down Expand Up @@ -35,7 +35,7 @@ exports[`for.melody.twig - melody-verify > for.melody.twig 1`] = `

`;

exports[`forIfElse.melody.twig - melody-verify > forIfElse.melody.twig 1`] = `
exports[`forIfElse.melody.twig - twig-verify > forIfElse.melody.twig 1`] = `
<ul>
{% for a,b in c | slice(3, c.length) if b is even -%}
<li>{{ a }} - {{ b }}</li>
Expand Down Expand Up @@ -75,7 +75,7 @@ exports[`forIfElse.melody.twig - melody-verify > forIfElse.melody.twig 1`] = `

`;

exports[`forInclude.melody.twig - melody-verify > forInclude.melody.twig 1`] = `
exports[`forInclude.melody.twig - twig-verify > forInclude.melody.twig 1`] = `
{% for foo in range(1, category) %}
<span key="{{ foo }}" class="qtp-item__star icon-ic icon-icn_star--white {{ foo }}">
{% include './Star.twig' only %}
Expand All @@ -91,7 +91,7 @@ exports[`forInclude.melody.twig - melody-verify > forInclude.melody.twig 1`] = `

`;

exports[`forWithBlock.melody.twig - melody-verify > forWithBlock.melody.twig 1`] = `
exports[`forWithBlock.melody.twig - twig-verify > forWithBlock.melody.twig 1`] = `
<h1>{{ title | title }}</h1>
<ul>
{% for item in items %}
Expand All @@ -118,7 +118,7 @@ exports[`forWithBlock.melody.twig - melody-verify > forWithBlock.melody.twig 1`]

`;

exports[`if.melody.twig - melody-verify > if.melody.twig 1`] = `
exports[`if.melody.twig - twig-verify > if.melody.twig 1`] = `
<div>
{%- if foo %}
<div class="foo"></div>
Expand Down
2 changes: 1 addition & 1 deletion tests/ControlStructures/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(__dirname, ["melody"]);
run_spec(__dirname, ["twig"]);
2 changes: 1 addition & 1 deletion tests/Declaration/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`doctype.melody.twig - melody-verify > doctype.melody.twig 1`] = `
exports[`doctype.melody.twig - twig-verify > doctype.melody.twig 1`] = `
<!DOCTYPE html>

<! DOCTYPE html>
Expand Down
2 changes: 1 addition & 1 deletion tests/Declaration/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(__dirname, ["melody"]);
run_spec(__dirname, ["twig"]);
20 changes: 10 additions & 10 deletions tests/Element/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`attributes.melody.twig - melody-verify > attributes.melody.twig 1`] = `
exports[`attributes.melody.twig - twig-verify > attributes.melody.twig 1`] = `
<a href="#abcd" target="_blank" lang="en" >Link</a>

<fantasy {{ {
Expand Down Expand Up @@ -35,7 +35,7 @@ exports[`attributes.melody.twig - melody-verify > attributes.melody.twig 1`] = `

`;

exports[`breakingSiblings.melody.twig - melody-verify > breakingSiblings.melody.twig 1`] = `
exports[`breakingSiblings.melody.twig - twig-verify > breakingSiblings.melody.twig 1`] = `
<span>One</span><b>Two</b><i>Three</i><span>Four</span><b>Five</b><i>Six</i><span>Seven</span>

<span>One</span>
Expand All @@ -60,7 +60,7 @@ exports[`breakingSiblings.melody.twig - melody-verify > breakingSiblings.melody.

`;

exports[`children.melody.twig - melody-verify > children.melody.twig 1`] = `
exports[`children.melody.twig - twig-verify > children.melody.twig 1`] = `
<div class="{{ css.loader }}">
<div class="{{ css.barWrapper }}">
<span class="{{ css.bar }}"></span>
Expand All @@ -77,7 +77,7 @@ exports[`children.melody.twig - melody-verify > children.melody.twig 1`] = `

`;

exports[`emptyLines.melody.twig - melody-verify > emptyLines.melody.twig 1`] = `
exports[`emptyLines.melody.twig - twig-verify > emptyLines.melody.twig 1`] = `
<div>
<img src="/img/posts/08/07/dns-resolution-expl.png" alt="DNS explained">

Expand Down Expand Up @@ -105,14 +105,14 @@ exports[`emptyLines.melody.twig - melody-verify > emptyLines.melody.twig 1`] = `

`;

exports[`extraSpaces.melody.twig - melody-verify > extraSpaces.melody.twig 1`] = `
exports[`extraSpaces.melody.twig - twig-verify > extraSpaces.melody.twig 1`] = `
<span >Text</span >
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<span>Text</span>

`;

exports[`manyAttributes.melody.twig - melody-verify > manyAttributes.melody.twig 1`] = `
exports[`manyAttributes.melody.twig - twig-verify > manyAttributes.melody.twig 1`] = `
<span attr1="one" attr2="two" attr3="three" attr4="four" attr5="five" attr6="six" attr7="seven" attr8="eight">Text</span>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<span attr1="one"
Expand All @@ -128,7 +128,7 @@ exports[`manyAttributes.melody.twig - melody-verify > manyAttributes.melody.twig

`;

exports[`oneLine.melody.twig - melody-verify > oneLine.melody.twig 1`] = `
exports[`oneLine.melody.twig - twig-verify > oneLine.melody.twig 1`] = `
<a href="{{ url }}">
Next
</a>
Expand All @@ -137,7 +137,7 @@ exports[`oneLine.melody.twig - melody-verify > oneLine.melody.twig 1`] = `

`;

exports[`selfClosing.melody.twig - melody-verify > selfClosing.melody.twig 1`] = `
exports[`selfClosing.melody.twig - twig-verify > selfClosing.melody.twig 1`] = `
<input type="text" name="user" />

<input attr1="one" attr2="two" attr3="three" attr4="four" attr5="five" attr6="six" attr7="seven" attr8="eight" />
Expand All @@ -161,14 +161,14 @@ exports[`selfClosing.melody.twig - melody-verify > selfClosing.melody.twig 1`] =

`;

exports[`siblings.melody.twig - melody-verify > siblings.melody.twig 1`] = `
exports[`siblings.melody.twig - twig-verify > siblings.melody.twig 1`] = `
<span>One</span><b>Two</b><i>Three</i>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<span>One</span><b>Two</b><i>Three</i>

`;

exports[`whitespace.melody.twig - melody-verify > whitespace.melody.twig 1`] = `
exports[`whitespace.melody.twig - twig-verify > whitespace.melody.twig 1`] = `
<span class="price">{{ price }} {{ currencySymbol }}</span>

<span class="price">Price: {{ price }} {{ currencySymbol }} per night</span>
Expand Down
2 changes: 1 addition & 1 deletion tests/Element/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(__dirname, ["melody"]);
run_spec(__dirname, ["twig"]);
22 changes: 11 additions & 11 deletions tests/Expressions/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`arrayExpression.melody.twig - melody-verify > arrayExpression.melody.twig 1`] = `
exports[`arrayExpression.melody.twig - twig-verify > arrayExpression.melody.twig 1`] = `
{{ [2, 3, "cat"] }}

{{ [ 2, 3, "cat","dog", "mouse"] }}
Expand Down Expand Up @@ -42,7 +42,7 @@ exports[`arrayExpression.melody.twig - melody-verify > arrayExpression.melody.tw

`;

exports[`binaryExpressions.melody.twig - melody-verify > binaryExpressions.melody.twig 1`] = `
exports[`binaryExpressions.melody.twig - twig-verify > binaryExpressions.melody.twig 1`] = `
{% set highlightValueForMoney = isFeatureEnabled('vFMV5') or isCTestActive('WEB-48935') or isCTestActive('WEB-48956') or isCTestActive('WEB-48955')%}

{% set name = condition1 or condition2 and condition3 or condition4 or condition5 and condition6 %}
Expand Down Expand Up @@ -95,7 +95,7 @@ exports[`binaryExpressions.melody.twig - melody-verify > binaryExpressions.melod

`;

exports[`callExpression.melody.twig - melody-verify > callExpression.melody.twig 1`] = `
exports[`callExpression.melody.twig - twig-verify > callExpression.melody.twig 1`] = `
{{ range(3) }}

{{ date('d/m/Y H:i', timezone="Europe/Paris") }}
Expand Down Expand Up @@ -155,7 +155,7 @@ exports[`callExpression.melody.twig - melody-verify > callExpression.melody.twig

`;

exports[`conditionalExpression.melody.twig - melody-verify > conditionalExpression.melody.twig 1`] = `
exports[`conditionalExpression.melody.twig - twig-verify > conditionalExpression.melody.twig 1`] = `
{{ test ? "One" : "Two" }}

{{ test ? "This is a slightly longer string to overflow the line" : "and here is its counterpart" }}
Expand All @@ -172,7 +172,7 @@ exports[`conditionalExpression.melody.twig - melody-verify > conditionalExpressi

`;

exports[`filterExpression.melody.twig - melody-verify > filterExpression.melody.twig 1`] = `
exports[`filterExpression.melody.twig - twig-verify > filterExpression.melody.twig 1`] = `
{{ 'test.foo' | split('.') }}
{{ range(3) | sort | join(',') }}
{{ 'SHOUTING' | lower|escape('html') | upper | escape('markdown') | lower | upper | escape('markdown') }}
Expand Down Expand Up @@ -224,14 +224,14 @@ exports[`filterExpression.melody.twig - melody-verify > filterExpression.melody.

`;

exports[`memberExpression.melody.twig - melody-verify > memberExpression.melody.twig 1`] = `
exports[`memberExpression.melody.twig - twig-verify > memberExpression.melody.twig 1`] = `
{{ alternativeMarriottRewardRates[deal.dealId].short }}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{{ alternativeMarriottRewardRates[deal.dealId].short }}

`;

exports[`objectExpression.melody.twig - melody-verify > objectExpression.melody.twig 1`] = `
exports[`objectExpression.melody.twig - twig-verify > objectExpression.melody.twig 1`] = `
{{ {
a: "foo",
"b#{ar}": "bar",
Expand Down Expand Up @@ -260,7 +260,7 @@ exports[`objectExpression.melody.twig - melody-verify > objectExpression.melody.

`;

exports[`operators.melody.twig - melody-verify > operators.melody.twig 1`] = `
exports[`operators.melody.twig - twig-verify > operators.melody.twig 1`] = `
{{ a b-and b }}
{{ a b-or b }}
{{ a b-xor b }}
Expand Down Expand Up @@ -392,7 +392,7 @@ exports[`operators.melody.twig - melody-verify > operators.melody.twig 1`] = `

`;

exports[`stringConcat.melody.twig - melody-verify > stringConcat.melody.twig 1`] = `
exports[`stringConcat.melody.twig - twig-verify > stringConcat.melody.twig 1`] = `
<div>
{{ first ~ second }}
</div>
Expand Down Expand Up @@ -423,7 +423,7 @@ exports[`stringConcat.melody.twig - melody-verify > stringConcat.melody.twig 1`]

`;

exports[`stringLiteral.melody.twig - melody-verify > stringLiteral.melody.twig 1`] = `
exports[`stringLiteral.melody.twig - twig-verify > stringLiteral.melody.twig 1`] = `
{{ 'zzz\\\\bar\\\\baz' }}

{{ "College - Women's" }}
Expand All @@ -446,7 +446,7 @@ exports[`stringLiteral.melody.twig - melody-verify > stringLiteral.melody.twig 1

`;

exports[`unaryNot.melody.twig - melody-verify > unaryNot.melody.twig 1`] = `
exports[`unaryNot.melody.twig - twig-verify > unaryNot.melody.twig 1`] = `
{% if not invalid %}
<p>All's well.</p>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion tests/Expressions/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
run_spec(__dirname, ["melody"]);
run_spec(__dirname, ["twig"]);
4 changes: 2 additions & 2 deletions tests/Failing/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`controversial.melody.twig - melody-verify > controversial.melody.twig 1`] = `
exports[`controversial.melody.twig - twig-verify > controversial.melody.twig 1`] = `
{% set isRewardRate = isMarriottRewardRate or (rewardRateAltIds and deal.dealId in rewardRateAltIds[accommodation.id.id]) %}

<!-- Alternatively, introduce another variable -->
Expand Down Expand Up @@ -89,7 +89,7 @@ exports[`controversial.melody.twig - melody-verify > controversial.melody.twig 1

`;

exports[`failing.melody.twig - melody-verify > failing.melody.twig 1`] = `
exports[`failing.melody.twig - twig-verify > failing.melody.twig 1`] = `
{# IF tag in element not allowed
<option {% if not purchasable.isAvailable %}disabled{% endif %}>
{{ purchasable.description }}
Expand Down
2 changes: 1 addition & 1 deletion tests/Failing/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
run_spec(__dirname, ["melody"], {
run_spec(__dirname, ["twig"], {
twigPrintWidth: 120,
twigAlwaysBreakObjects: true,
twigFollowOfficialCodingStandards: false
Expand Down
Loading