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

Upgrade babel, add importAttributesKeyword parameter #293

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@
},
"license": "Apache-2.0",
"dependencies": {
"@babel/generator": "7.17.7",
"@babel/parser": "^7.20.5",
"@babel/traverse": "7.23.2",
"@babel/types": "7.17.0",
"@babel/generator": "7.24.4",
"@babel/parser": "^7.24.4",
"@babel/traverse": "7.24.1",
"@babel/types": "7.24.0",
"javascript-natural-sort": "0.7.1",
"lodash": "^4.17.21"
},
"devDependencies": {
"@babel/core": "^7.20.7",
"@babel/core": "^7.24.4",
"@types/chai": "4.2.15",
"@types/jest": "26.0.20",
"@types/lodash": "4.14.168",
"@types/node": "20.8.6",
"@vue/compiler-sfc": "^3.2.41",
"@vue/compiler-sfc": "3.2.41",
"jest": "26.6.3",
"prettier": "2.8",
"ts-jest": "26.5.3",
Expand Down
1 change: 1 addition & 0 deletions src/utils/__tests__/get-code-from-ast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import a from 'a';
expect(format(formatted, { parser: 'babel' })).toEqual(
`// first comment
// second comment

import a from "a";
import c from "c";
import g from "g";
Expand Down
2 changes: 1 addition & 1 deletion src/utils/extract-ast-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function extractASTNodes(ast: ParseResult<File>) {

ImportDeclaration(path: NodePath<ImportDeclaration>) {
const tsModuleParent = path.findParent((p) =>
isTSModuleDeclaration(p),
isTSModuleDeclaration(p.node),
);
if (!tsModuleParent) {
importNodes.push(path.node);
Expand Down
11 changes: 7 additions & 4 deletions src/utils/get-code-from-ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,22 @@ export const getCodeFromAst = (
directives,
sourceType: 'module',
interpreter: interpreter,
sourceFile: '',
leadingComments: [],
innerComments: [],
trailingComments: [],
start: 0,
end: 0,
loc: {
start: { line: 0, column: 0 },
end: { line: 0, column: 0 },
filename: '',
identifierName: '',
start: { line: 0, column: 0, index: 0 },
end: { line: 0, column: 0, index: 0 },
},
});

const { code } = generate(newAST);
const { code } = generate(newAST, {
importAttributesKeyword: 'with',
});

return (
code.replace(
Expand Down
2 changes: 1 addition & 1 deletion src/utils/get-import-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const getImportNodes = (code: string, options?: ParserOptions) => {
traverse(ast, {
ImportDeclaration(path: NodePath<ImportDeclaration>) {
const tsModuleParent = path.findParent((p) =>
isTSModuleDeclaration(p),
isTSModuleDeclaration(p.node),
);
if (!tsModuleParent) {
importNodes.push(path.node);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/is-sort-imports-ignored.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { getAllCommentsFromNodes } from './get-all-comments-from-nodes';
export const isSortImportsIgnored = (nodes: Statement[]) =>
getAllCommentsFromNodes(nodes).some(
(comment) =>
comment.loc.start.line === 1 &&
comment.loc?.start.line === 1 &&
comment.value.includes(sortImportsIgnoredComment),
);
1 change: 1 addition & 0 deletions tests/Babel/__snapshots__/ppsi.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function add(a,b) {
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment in this file.

import thirdParty from "third-party";
import z from "z";

Expand Down
2 changes: 2 additions & 0 deletions tests/Flow/__snapshots__/ppsi.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export function givesAFoo3Obj(): AliasFoo3 {
/**
* @flow
*/

// I am top level comment in this file.

import thirdParty from "third-party";

import abc from "@core/abc";
Expand Down
5 changes: 5 additions & 0 deletions tests/ImportsNotSeparated/__snapshots__/ppsi.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function add(a:number,b:number) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment in this file.
// I am second line of top level comment in this file.

import React from "react";
import "./commands";

Expand Down Expand Up @@ -131,6 +132,7 @@ function add(a:number,b:number) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment in this file.
// I am second line of top level comment in this file.

import thirdParty from "third-party";
import z from "z";
import abc from "@core/abc";
Expand Down Expand Up @@ -245,6 +247,7 @@ function add(a:number,b:number) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//@ts-ignore
// I am file top level comments

import a from "a";
import c from "c";
// I am stick to third party comment
Expand Down Expand Up @@ -323,6 +326,7 @@ import fourLevelRelativePath from "../../../../fourLevelRelativePath";
import something from "@server/something";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment

import abc from "@core/abc";
import otherthing from "@core/otherthing";
import something from "@server/something";
Expand Down Expand Up @@ -378,6 +382,7 @@ import './commands';
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import "./commands";

Expand Down
5 changes: 5 additions & 0 deletions tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function add(a:number,b:number) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment in this file.
// I am second line of top level comment in this file.

import React from "react";
import "./commands";

Expand Down Expand Up @@ -131,6 +132,7 @@ function add(a:number,b:number) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment in this file.
// I am second line of top level comment in this file.

import abc from "@core/abc";
import otherthing from "@core/otherthing";
import qwerty from "@server/qwerty";
Expand Down Expand Up @@ -188,6 +190,7 @@ function add(a:number,b:number) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//@ts-ignore
// I am file top level comments

import otherthing from "@core/otherthing";
import something from "@server/something";
import component from "@ui/hello";
Expand Down Expand Up @@ -266,6 +269,7 @@ import fourLevelRelativePath from "../../../../fourLevelRelativePath";
import something from "@server/something";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment

import abc from "@core/abc";
import otherthing from "@core/otherthing";
import something from "@server/something";
Expand Down Expand Up @@ -321,6 +325,7 @@ import './commands';
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import "./commands";

Expand Down
6 changes: 6 additions & 0 deletions tests/ImportsSeparated/__snapshots__/ppsi.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function add(a:number,b:number) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment in this file.
// I am second line of top level comment in this file.

import React from "react";

import "./commands";
Expand Down Expand Up @@ -136,6 +137,7 @@ function add(a:number,b:number) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment in this file.
// I am second line of top level comment in this file.

import thirdParty from "third-party";
import z from "z";

Expand Down Expand Up @@ -196,6 +198,7 @@ const workletAdd = (a:number,b:number) => {
"use client";

// comment after directives

import abc from "@core/abc";
import otherthing from "@core/otherthing";

Expand Down Expand Up @@ -262,6 +265,7 @@ function add(a:number,b:number) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//@ts-ignore
// I am file top level comments

import a from "a";
import c from "c";
// I am stick to third party comment
Expand Down Expand Up @@ -347,6 +351,7 @@ import fourLevelRelativePath from "../../../../fourLevelRelativePath";
import something from "@server/something";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment

import abc from "@core/abc";
import otherthing from "@core/otherthing";

Expand Down Expand Up @@ -405,6 +410,7 @@ import './commands';
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import "./commands";

Expand Down
5 changes: 5 additions & 0 deletions tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function add(a:number,b:number) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment in this file.
// I am second line of top level comment in this file.

import React from "react";

import "./commands";
Expand Down Expand Up @@ -136,6 +137,7 @@ function add(a:number,b:number) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment in this file.
// I am second line of top level comment in this file.

import abc from "@core/abc";
import otherthing from "@core/otherthing";

Expand Down Expand Up @@ -197,6 +199,7 @@ function add(a:number,b:number) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//@ts-ignore
// I am file top level comments

import otherthing from "@core/otherthing";

import something from "@server/something";
Expand Down Expand Up @@ -282,6 +285,7 @@ import fourLevelRelativePath from "../../../../fourLevelRelativePath";
import something from "@server/something";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment

import abc from "@core/abc";
import otherthing from "@core/otherthing";

Expand Down Expand Up @@ -340,6 +344,7 @@ import './commands';
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import "./commands";

Expand Down
4 changes: 4 additions & 0 deletions tests/Vue/__snapshots__/ppsi.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function add(a,b) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<script setup>
// I am top level comment in this file.

import thirdParty from "third-party";
import { defineComponent } from "vue";
import z from "z";
Expand Down Expand Up @@ -85,6 +86,7 @@ export default defineComponent({
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<script>
// I am top level comment in this file.

import thirdParty from "third-party";
import { defineComponent } from "vue";
import z from "z";
Expand Down Expand Up @@ -165,6 +167,7 @@ export default defineComponent({
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<script lang="ts">
// I am top level comment in this file.

import thirdParty from "third-party";
import { defineComponent } from "vue";
import z from "z";
Expand Down Expand Up @@ -222,6 +225,7 @@ export default defineComponent({
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<script lang="tsx">
// I am top level comment in this file.

import thirdParty from "third-party";
import { defineComponent } from "vue";
import z from "z";
Expand Down
Loading
Loading