Skip to content

Commit 2c3217f

Browse files
authored
Merge pull request #78 from gitKrystan/prettier-3
2 parents c8365ab + 2bcee59 commit 2c3217f

20 files changed

Lines changed: 4715 additions & 4723 deletions

.prettierrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ module.exports = {
22
plugins: ['prettier-plugin-jsdoc'],
33
singleQuote: true,
44
tsdoc: true,
5+
6+
// TODO: Remove this in the next PR
7+
trailingComma: 'es5',
58
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { Printer, SupportLanguage, SupportOptions } from 'prettier';
2+
3+
declare const printers: {
4+
estree: Printer;
5+
'estree-json': Printer;
6+
};
7+
8+
declare const languages: SupportLanguage[];
9+
10+
declare const options: SupportOptions;

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
A [Prettier](https://prettier.io/) plugin for formatting [Ember template tags](https://rfcs.emberjs.com/id/0779-first-class-component-templates/) in both `.gjs` and `.gts` files. See also [Ember Template Imports](https://github.com/ember-template-imports/ember-template-imports).
88

9+
## Compatibility
10+
11+
Prettier 3.0.0 and above
12+
913
## Usage
1014

1115
1. Install:

examples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"example-ts": "pnpm exec prettier --write ./example.gts"
88
},
99
"dependencies": {
10-
"prettier": "^2.8.8",
10+
"prettier": "^3.0.0",
1111
"prettier-plugin-ember-template-tag": "workspace:^"
1212
}
1313
}

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"@glimmer/syntax": "^0.84.3",
5555
"ember-cli-htmlbars": "^6.2.0",
5656
"ember-template-imports": "^3.4.2",
57-
"prettier": "^2.8.8"
57+
"prettier": "^3.0.0"
5858
},
5959
"devDependencies": {
6060
"@babel/types": "^7.22.5",
@@ -64,7 +64,6 @@
6464
"@types/babel__core": "^7.20.1",
6565
"@types/eslint": "^8.44.0",
6666
"@types/node": "^20.4.4",
67-
"@types/prettier": "^2.7.3",
6867
"@typescript-eslint/eslint-plugin": "^6.1.0",
6968
"@typescript-eslint/parser": "^6.1.0",
7069
"@vitest/ui": "^0.33.0",
@@ -76,12 +75,15 @@
7675
"eslint-plugin-n": "^16.0.1",
7776
"eslint-plugin-unicorn": "^48.0.0",
7877
"eslint-plugin-vitest": "^0.2.6",
79-
"prettier-plugin-jsdoc": "^0.4.2",
78+
"prettier-plugin-jsdoc": "^1.0.1",
8079
"release-it": "^16.1.3",
8180
"typescript": "^5.1.6",
8281
"vite": "^4.4.6",
8382
"vitest": "^0.33.0"
8483
},
84+
"peerDependencies": {
85+
"prettier": ">3.0.0"
86+
},
8587
"engines": {
8688
"node": "16.* || 18.* || >= 20"
8789
},

pnpm-lock.yaml

Lines changed: 14 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/options.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ export interface Options extends ParserOptions<Node | undefined> {
1212
}
1313

1414
const templateExportDefault: BooleanSupportOption = {
15-
since: '0.1.0',
1615
category: 'Format',
1716
type: 'boolean',
1817
default: false,
19-
description: 'Prepend default export template tags with "export default".',
18+
description:
19+
'Prepend default export template tags with "export default". Since 0.1.0.',
2020
};
2121

2222
/**
@@ -32,19 +32,17 @@ export function getTemplateSingleQuote(options: Options): boolean {
3232
}
3333

3434
const templateSingleQuote: BooleanSupportOption = {
35-
since: '0.0.3',
3635
category: 'Format',
3736
type: 'boolean',
3837
description:
39-
'Use single quotes instead of double quotes within template tags.',
38+
'Use single quotes instead of double quotes within template tags. Since 0.0.3.',
4039
};
4140

4241
const __inputWasPreprocessed: BooleanSupportOption = {
43-
since: '0.1.0',
4442
category: 'Format',
4543
type: 'boolean',
4644
description:
47-
'Internal: If true, the template was preprocessed before being run through Prettier.',
45+
'Internal: If true, the template was preprocessed before being run through Prettier. Since 0.1.0.',
4846
};
4947

5048
export const options: SupportOptions = {

src/parse.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ import {
99
import { getTemplateLocals } from '@glimmer/syntax';
1010
import { preprocessEmbeddedTemplates } from 'ember-template-imports/lib/preprocess-embedded-templates';
1111
import type { Parser } from 'prettier';
12-
import { parsers as babelParsers } from 'prettier/parser-babel';
12+
import { parsers as babelParsers } from 'prettier/plugins/babel';
1313
import {
1414
PRINTER_NAME,
1515
TEMPLATE_TAG_NAME,
1616
TEMPLATE_TAG_PLACEHOLDER,
1717
} from './config';
1818
import type { Options } from './options';
19-
import { definePrinter } from './print/index';
2019
import type {
2120
GlimmerExpressionExtra,
2221
GlimmerTemplateExtra,
@@ -75,17 +74,12 @@ export const parser: Parser<Node | undefined> = {
7574
astFormat: PRINTER_NAME,
7675

7776
preprocess(text: string, options: Options): string {
78-
definePrinter(options);
7977
const js = preprocess(text, options);
8078
return typescript.preprocess?.(js, options) ?? js;
8179
},
8280

83-
parse(
84-
text: string,
85-
parsers: Record<string, Parser<unknown>>,
86-
options: Options
87-
): Node {
88-
const ast = typescript.parse(text, parsers, options);
81+
async parse(text: string, options: Options): Promise<Node> {
82+
const ast = await typescript.parse(text, options);
8983
assert('expected ast', ast);
9084
traverse(ast, {
9185
enter: makeEnter(options),

0 commit comments

Comments
 (0)