Commit Graph

12 Commits (82257bc091b7d2ec0d4bfb36e3ea3a9329680cba)

Author SHA1 Message Date
Wei-Wei Wu 91c20f7fbe Rename "babylon" with "babel" (#5647) 2018-12-27 21:05:19 +08:00
Lucas Duailibe f119d4a90f
Change run_spec to have explicit parser list (#3356) 2017-11-30 03:31:52 -03:00
Lucas Azzola 486a89bfdc fix(typescript): workaround - don't wrap directives in parens, fixes #2074 (#2107) 2017-06-11 19:10:56 -07:00
Lucas Azzola 2f840f940f test(typescript): disable failing tests (#1782) 2017-05-27 18:22:32 -07:00
Lucas Azzola 2a58e6bc06 test(typescript): enable typescript-verify on most tests (#1781) 2017-05-27 17:57:07 -07:00
Joseph Frazier 8cc38ad524 Preserve code unit sequence of directive literals (#1571)
* Print directive literals verbatim

This addresses https://github.com/prettier/prettier/issues/1555,
but doesn't seem to pass the AST_COMPARE=1 tests:

    AST_COMPARE=1 npm test -- tests/quotes -t strings

However, running `prettier --debug-check` on the relevant file *does*
work:

    prettier tests/quotes/strings.js --debug-check

* Change directive literal quotes if it doesn't contain quotes

This addresses https://github.com/prettier/prettier/pull/1560#discussion_r115396257

From https://github.com/prettier/prettier/issues/1555#issue-227206837:

> It's okay to change the type of quotation marks used, but only if
doing so does not require changing any characters within the directive.

* Don't change directive literal quotes if it contains a backslash

This passes the `--debug-check` tests again:

    prettier tests/quotes/strings.js --debug-check

* Try to add regression test for escaped directive literals

This seems not to work, despite the following command having the correct
output:

    echo "'\''" | prettier

You can use the following to get an idea of how flow/typescript parse
this:

    node -p "JSON.stringify(require('./src/parser').parse('\\'\\\\\'\\'', {parser: 'flow'}), null, 2)"
    node -p "JSON.stringify(require('./src/parser').parse('\\'\\\\\'\\'', {parser: 'typescript'}), null, 2)"

* WIP Disable Flow/Typescript for ./tests/directives

We don't yet handle escaped directives for them, but Babylon works.

(similar to 90bf93713c (diff-0de18284f37da79ab8af4e4690919abaR1))

* Revert "WIP Disable Flow/Typescript for ./tests/directives"

This reverts commit 2aba6231271f6985a395c31e3df9323e8f3da115.

* Prevent test strings from being parsed as directives

See https://github.com/prettier/prettier/pull/1560#issue-227225960

* Add more escaped directive tests

* Infer DirectiveLiterals from Flow parser

* Don't test TypeScript on directives

See https://github.com/prettier/prettier/pull/1560#issuecomment-300296221

* fixup! Infer DirectiveLiterals from Flow parser

* Don't fake objects that look like a DirectiveLiteral

Instead, add a flag to nodeStr() that deals with the Flow node
accordingly. See https://github.com/prettier/prettier/pull/1560#discussion_r115605758

* Print preferred quotes around escaped DirectiveLiteral when it doesn't contain quotes

See https://github.com/prettier/prettier/pull/1560#discussion_r115606122

* Simplify `canChangeDirectiveQuotes` logic

* Add directive test with unnecessarily escaped non-quote character

* Fix boolean logic error

I thought that this would result in the following if-block executing, as
needed to pass the test case in the previous commit. However, it appears
that it's not actually needed to pass the test case, since `makeString`
doesn't unescape unnecessarily escaped non-quote characters.
Nevertheless, I think we should leave that if-block (`if (canChangeDirectiveQuotes)`)
there, in case `makeString` is updated.

See https://github.com/prettier/prettier/pull/1571#discussion_r115658398

* Make isFlowDirectiveLiteral a separate argument to nodeStr()

See https://github.com/prettier/prettier/pull/1571#discussion_r115810988

* Simplify isFlowDirectiveLiteral logic by passing n.expression to nodeStr()

See https://github.com/prettier/prettier/pull/1571#discussion_r115811216
2017-05-10 12:15:27 -07:00
Christopher Chedeau 13f247aee3 Revert "Print directive literals verbatim (#1560)" (#1570)
This reverts commit 32d9d68154.
2017-05-09 14:19:03 -07:00
Joseph Frazier 32d9d68154 Print directive literals verbatim (#1560)
* Print directive literals verbatim

This addresses https://github.com/prettier/prettier/issues/1555,
but doesn't seem to pass the AST_COMPARE=1 tests:

    AST_COMPARE=1 npm test -- tests/quotes -t strings

However, running `prettier --debug-check` on the relevant file *does*
work:

    prettier tests/quotes/strings.js --debug-check

* Change directive literal quotes if it doesn't contain quotes

This addresses https://github.com/prettier/prettier/pull/1560#discussion_r115396257

From https://github.com/prettier/prettier/issues/1555#issue-227206837:

> It's okay to change the type of quotation marks used, but only if
doing so does not require changing any characters within the directive.

* Don't change directive literal quotes if it contains a backslash

This passes the `--debug-check` tests again:

    prettier tests/quotes/strings.js --debug-check

* Try to add regression test for escaped directive literals

This seems not to work, despite the following command having the correct
output:

    echo "'\''" | prettier

You can use the following to get an idea of how flow/typescript parse
this:

    node -p "JSON.stringify(require('./src/parser').parse('\\'\\\\\'\\'', {parser: 'flow'}), null, 2)"
    node -p "JSON.stringify(require('./src/parser').parse('\\'\\\\\'\\'', {parser: 'typescript'}), null, 2)"

* WIP Disable Flow/Typescript for ./tests/directives

We don't yet handle escaped directives for them, but Babylon works.

(similar to 90bf93713c (diff-0de18284f37da79ab8af4e4690919abaR1))

* Revert "WIP Disable Flow/Typescript for ./tests/directives"

This reverts commit 2aba6231271f6985a395c31e3df9323e8f3da115.

* Prevent test strings from being parsed as directives

See https://github.com/prettier/prettier/pull/1560#issue-227225960

* Add more escaped directive tests

* Infer DirectiveLiterals from Flow parser

* Don't test TypeScript on directives

See https://github.com/prettier/prettier/pull/1560#issuecomment-300296221

* fixup! Infer DirectiveLiterals from Flow parser
2017-05-09 17:17:29 -04:00
ChristianHersevoort 04c959d687 Feature/verify against same snapshot (#1087)
* Verify parsers against same snapshot

- Reworked run_spec, now accepts 3th optional array argument for
additional parsers to verify against
- Merged duplicate run_spec configs
- Removed duplicate snapshot data

* Formatted run_spec.js with prettier

* Fixed node4 incompatibility
2017-03-25 08:10:17 -07:00
James Henry 72456bf06f [WIP] TypeScript Parser (#915)
* WIP immediate feedback

* typescript parser is drop-in replacement for flow parser

* Add new TypeScript Parser snapshots where drop-in replacement possible

* Snapshot updates after rebasing

* Remove unnecessary stripping of properties on TypeScript parser AST

* Remove annotated issues

* Move TS dependencies to dev for now
2017-03-08 13:18:13 -08:00
Christopher Chedeau 1334dbc781 Preserve new lines after directives (#464)
It's annoying that the line after `"use strict";` gets eaten away on babylon. This fixes it :)

Fixes #216
2017-01-25 16:26:09 -05:00
Christopher Chedeau 3375cfe605 Move tests around (#454)
* new_tests

* move_all_clobbered_tests

* remove all the tests that no longer exist

* re-run flow tests

* Move all the flow tests to tests/flow and prettier to tests/

* Move prettier tests to their own folders

* Add jsfmt files

* run prettier snapshot tests
2017-01-24 14:35:37 -08:00