Commit Graph
34 Commits
Author SHA1 Message Date
Cyrille 2f9663b6fa Refactor and use getPreferredQuote in both jsx and handlebars printers (#11569)
* raw => rawContent

* Refactor getPreferredQuote

Exposing { quote, regex, escaped } from the getPreferredQuote return
value allows us to simplify a bit the code in the printer.

* Use the common/util function

And remove chooseEnclosingQuote

* Move favoriteQuote

* Fix lint

* Remove enclosing quotes _before_ unescape
2021-09-24 06:32:32 +09:00
Cyrille David 3cd28ca80d Preserve attributes order for element node (#10958)
* Preserve attributes order for element node

* Add CHANGELOG

* Add ...arguments in the test

* Apply fisker suggestions

* Simplify further
2021-06-04 13:54:02 +03:00
Cyrille David 4407d7b1ea Ember / Handlebars: Do not break opening mustache and path (#10586)
* Add failing tests

* Simplify how mustaches are printed

* Add changelog entry

* Fix changelog

* Make test fail

* Remove a wrong group

* Remove another group

* Record the tests
2021-03-29 15:59:19 +03:00
Cyrille DavidandGeorgii Dolzhykov f6b63e8807 Move Handlebars support out of alpha to release (#10290)
Co-authored-by: Georgii Dolzhykov <thorn.mailbox@gmail.com>
2021-03-16 11:25:06 +02:00
Cyrille David 5aa057b40b Handlebars: Default --html-whitespace-sensitivity to strict (#10201)
* Handlebars: Default --html-whitespace-sensitivity to strict

* Record tests other than handlebars

* Trim trailing newlines

* Record tests

* Fix rebase

* Record all tests not only hbs

* Fix the idempotency issue

Adjust dedent for the last child node

* Fix the annoying trailing whitespace

* Trim isolated leading newline
2021-02-11 15:43:07 +02:00
Cyrille David 091e91e50d Handlebars printer: two small refactorings (#10285)
* Refactor generateHardlines

* Move variables

* Fix isWhitespaceOnly regex
2021-02-09 21:49:31 +02:00
Cyrille Davidandfisker Cheung 8198f40727 handlebars: Split text content on multiple lines (#10179)
Co-authored-by: fisker Cheung <lionkay@gmail.com>
2021-02-07 08:58:44 +08:00
Cyrille David 0d1713ba81 Add changelog entry for #9885 (#10133) 2021-01-25 21:27:35 +02:00
Cyrille DavidandGeorgii Dolzhykov 949c36190f Document --htmlWhitespaceSensitivity option for Handlebars (#10079)
* Document htmlWhitespaceSensitivity for Handlebars

* Update options.md

Co-authored-by: Georgii Dolzhykov <thorn.mailbox@gmail.com>
2021-01-19 16:49:19 +02:00
Cyrille David c8cbbb0a79 handlebars: Support htmlWhitespaceSensitivity=strict option (2/3) (#9885)
* hbs: Add a strict mode

* Fix lint (after concat removal)

* Another lint error
2021-01-18 15:49:39 +02:00
Cyrille David 554d45ea20 handlebars: Print final blockParam on its own line (#9978) 2021-01-13 12:02:47 +08:00
Cyrille David fbe57068e7 Handlebars: Add tests for ignore and strict modes (1/3) (#9883) 2020-12-21 17:04:18 +08:00
Cyrille David ca68cbe731 Refactor and inline handlebars' postprocess file in parser file (#9021) 2020-08-22 11:35:51 +08:00
Cyrille David 8013e510cc handlebars: Remove duplicated tests (#9020) 2020-08-22 11:35:24 +08:00
Cyrille ed9d399a47 handlebars: Do not format html element attributes but class (#8677) 2020-07-24 00:40:35 +08:00
Cyrille 2ff388f19a Add a test (#8721) 2020-07-13 18:25:52 +03:00
Cyrille David bff049fd96 handlebars: Support escaping a mustache with a backslash (#8634)
* Add a failing test

* Support escaping a mustache with `\`

It is documented in handlebarjs documentation here:
https://handlebarsjs.com/guide/expressions.html#escaping-handlebars-expressions

* Preprocess TextNode to adjust the need of backslashes

Given that template:
```hbs
a non-escaped mustache: \\\{{helper}}
```

Glimmer parser will produce two body nodes:
- a TextNode where `node.chars === "a non-escaped mustache: \\\\"`
- a MustacheStatement for `{{helper}}`

In order to correctly print the input, we need to adjust the TextNode to
`node.chars === "a non-escaped mustache: \\\\\\"`, namely we have to add
a backslash that is removed by Glimmer parser. This is this commit
purpose.

* Add changelog note
2020-06-24 23:55:02 +03:00
Cyrille David 40ade963a8 Respect singleQuote option around attribute value more complex than a bare text (#8375)
* Apply singleQuote option to attributes

* Add changelog
2020-05-25 13:18:49 +03:00
Cyrille David e398ccc66d Enable glimmer printer in the playground (#8373) 2020-05-22 19:13:49 +08:00
Cyrille Davidandfisker Cheung 36200ad518 Refactor glimmer-printer (#7967)
* Refactor isVoid to a function

* Move isVoid to utils

* Refactor isVoid function

* Simplify a ternary

* Refactor ElementNode / MustacheStatement

* Rename a function

* Refactor blockstatement

* Extract two functions from ElementNode

* Remove useless filter

* Use helpers in TextNode

* Refactor SubExpression

* Refactor BlockStatement

* Fix cspell CI job

* Update src/language-handlebars/printer-glimmer.js

Co-Authored-By: fisker Cheung <lionkay@gmail.com>

* Fix linting in CI

Co-authored-by: fisker Cheung <lionkay@gmail.com>
2020-04-08 02:44:12 +03:00
Cyrille David 057e93305b refactoring(glimmer): Create a clean file (#7529) 2020-02-04 02:32:14 +02:00
Cyrille David 7d42e79d9d refactoring(glimmer): Extract utils from printer (#7528)
* Extract isWhitespaceNode

* Refactor isParentOfType to isParentOfSomeType

* Introduce isNodeOfSomeType

* Replace isNextNodeOfType with isNextNodeOfSomeType

* Move utils to utils file

* Sort utils

* Refactor isPrettierIgnoreNode function to use util

* Extract hasPrettierIgnore to utils

* Apply review feedback

* Apply review suggestions

* Add getSiblingNode
2020-02-03 21:44:24 +02:00
Cyrille DavidandGeorgii Dolzhykov 9b684892d5 Upgrade @glimmer/syntax to latest (#7245)
* Remove simple-html-tokenizer resolution

* Remove outdated filter

I'm not 100% sure but I guess it was useful with previous
@glimmer/syntax versions

* Remove unused code

* Upgrade @glimmer/syntax and simple-html-tokenizen

Co-authored-by: Georgii Dolzhykov <thorn.mailbox@gmail.com>
2020-02-03 18:28:08 +02:00
Cyrille David 2662e542b5 Extract isGlimmerComponent to an util (#7483) 2020-02-03 13:44:37 +03:00
Cyrille David 97a878632c Support printing inline handlebars in html (through embed function) (#7306)
* Move old handlebars to html file

This kind of handlebars code is supposed to be in html files.

* Remove useless file

* Uglify our old handlebars file

* Move venerable hbs tests to their folder

Because of their config

* html: Use glimmer for script tags of type handlebars

* Record snapshots

* Add CHANGELOG entry

* Add the CHANGELOG test

* Make the PR changes more obvious
2020-01-21 08:55:29 +02:00
Cyrille David 0bb75fd1b9 handlebars: Fix superfluous line breaks in ConcatStatement (#7051) 2020-01-08 14:24:45 +02:00
Cyrille David c1b6e1c401 handlebars: Improve MustacheStatement printing (#7157)
* Address https://github.com/prettier/prettier/pull/7051#discussion_r351877770

* Add isParentOfType helper fun

* Add CHANGELOG

* Fix a typo

* CHANGELOG: Remove --print-width option

* Add tests
2020-01-05 18:36:34 +02:00
Cyrille David 456041526f glimmer: Split ElementModifierStatement and MustacheStatement (#7156) 2019-12-23 15:32:28 +03:00
Cyrille David 53c1049830 Refactor a few functions in glimmer printer (#7072) 2019-12-23 14:52:03 +03:00
Cyrille David 021eec8d73 Fix a falling mustache issue (#7052)
* Add a test highlighting the falling mustache issue

* Use concat helper instead of manual concat

* Fix the falling mustache issue

* Add a CHANGELOG
2019-11-28 17:12:57 +01:00
Cyrille David 61f4cbcf41 tests(handlebars): Move a test to handlebars folder (#6962)
This looks like a file left behind during a rebase. Let's move it to a
more logical location.
2019-11-19 10:57:47 +02:00
Cyrille David 7cb0c23774 fix(handlebars): Use quotes from config in AttrNode (#6377) 2019-09-30 17:08:58 +03:00
Cyrille David dd64842375 chore(Handlebars): Refactor test suite (#6378) 2019-08-12 10:35:13 -03:00
Cyrille David 84cc273c7d fix(glimmer): {{else}}{{#if}} into {{else if}} merging (#6080) 2019-05-02 16:26:26 +03:00