-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into blake.newman/make-vue-compiler-sfc-optional
- Loading branch information
Showing
12 changed files
with
242 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ParseResult } from '@babel/parser'; | ||
import traverse, { NodePath } from '@babel/traverse'; | ||
import { | ||
Directive, | ||
File, | ||
ImportDeclaration, | ||
isTSModuleDeclaration, | ||
} from '@babel/types'; | ||
|
||
export function extractASTNodes(ast: ParseResult<File>) { | ||
const importNodes: ImportDeclaration[] = []; | ||
const directives: Directive[] = []; | ||
traverse(ast, { | ||
Directive({ node }) { | ||
directives.push(node); | ||
|
||
// Trailing comments probably shouldn't be attached to the directive | ||
node.trailingComments = null; | ||
}, | ||
|
||
ImportDeclaration(path: NodePath<ImportDeclaration>) { | ||
const tsModuleParent = path.findParent((p) => | ||
isTSModuleDeclaration(p), | ||
); | ||
if (!tsModuleParent) { | ||
importNodes.push(path.node); | ||
} | ||
}, | ||
}); | ||
return { importNodes, directives }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
'use client'; | ||
import otherthing from "@core/otherthing"; | ||
import abc from "@core/abc"; | ||
// Comment | ||
function add(a:number,b:number) { | ||
return a + b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
'use client'; | ||
|
||
// comment after directives | ||
import otherthing from "@core/otherthing"; | ||
import abc from "@core/abc"; | ||
|
||
// Comment | ||
|
||
function add(a:number,b:number) { | ||
return a + b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,97 @@ | ||
import { ParserPlugin } from '@babel/parser'; | ||
import { Config } from 'prettier'; | ||
|
||
export type ImportOrderParserPlugin = | ||
| Extract<ParserPlugin, string> | ||
| `[${string},${string}]`; | ||
|
||
export interface PluginConfig { | ||
/** | ||
* A collection of Regular expressions in string format. | ||
* | ||
* ``` | ||
* "importOrder": ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"], | ||
* ``` | ||
* | ||
* _Default behavior:_ The plugin moves the third party imports to the top which are not part of the `importOrder` list. | ||
* To move the third party imports at desired place, you can use `<THIRD_PARTY_MODULES>` to assign third party imports to the appropriate position: | ||
* | ||
* ``` | ||
* "importOrder": ["^@core/(.*)$", "<THIRD_PARTY_MODULES>", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"], | ||
* ``` | ||
*/ | ||
importOrder: string[]; | ||
importOrderCaseInsensitive: boolean; | ||
// should be of type ParserPlugin from '@babel/parser' but prettier does not support nested arrays in options | ||
importOrderParserPlugins: string[]; | ||
importOrderSeparation: boolean; | ||
importOrderGroupNamespaceSpecifiers: boolean; | ||
importOrderSortSpecifiers: boolean; | ||
|
||
/** | ||
* A boolean value to enable or disable the new line separation | ||
* between sorted import declarations group. The separation takes place according to the `importOrder`. | ||
* | ||
* @default false | ||
*/ | ||
importOrderSeparation?: boolean; | ||
|
||
/** | ||
* A boolean value to enable or disable sorting of the specifiers in an import declarations. | ||
* | ||
* @default false | ||
*/ | ||
importOrderSortSpecifiers?: boolean; | ||
|
||
/** | ||
* A boolean value to enable or disable sorting the namespace specifiers to the top of the import group. | ||
* | ||
* @default false | ||
*/ | ||
importOrderGroupNamespaceSpecifiers?: boolean; | ||
|
||
/** | ||
* A boolean value to enable case-insensitivity in the sorting algorithm | ||
used to order imports within each match group. | ||
* | ||
* For example, when false (or not specified): | ||
* | ||
* ```js | ||
* import ExampleView from './ExampleView'; | ||
* import ExamplesList from './ExamplesList'; | ||
* ``` | ||
* | ||
* compared with `"importOrderCaseInsensitive": true`: | ||
* | ||
* ```js | ||
* import ExamplesList from './ExamplesList'; | ||
* import ExampleView from './ExampleView'; | ||
* ``` | ||
* | ||
* @default false | ||
*/ | ||
importOrderCaseInsensitive?: boolean; | ||
|
||
/** | ||
* Previously known as `experimentalBabelParserPluginsList`. | ||
* | ||
* A collection of plugins for babel parser. The plugin passes this list to babel parser, so it can understand the syntaxes | ||
* used in the file being formatted. The plugin uses prettier itself to figure out the parser it needs to use but if that fails, | ||
* you can use this field to enforce the usage of the plugins' babel parser needs. | ||
* | ||
* **To pass the plugins to babel parser**: | ||
* | ||
* ``` | ||
* "importOrderParserPlugins" : ["classProperties", "decorators-legacy"] | ||
* ``` | ||
* | ||
* **To pass the options to the babel parser plugins**: Since prettier options are limited to string, you can pass plugins | ||
* with options as a JSON string of the plugin array: | ||
* `"[\"plugin-name\", { \"pluginOption\": true }]"`. | ||
* | ||
* ``` | ||
* "importOrderParserPlugins" : ["classProperties", "[\"decorators\", { \"decoratorsBeforeExport\": true }]"] | ||
* ``` | ||
* | ||
* **To disable default plugins for babel parser, pass an empty array**: | ||
* | ||
* @default ["typescript", "jsx"] | ||
*/ | ||
importOrderParserPlugins?: ImportOrderParserPlugin[]; | ||
} | ||
|
||
export type PrettierConfig = PluginConfig & Config; |