diff --git a/src/packages/v2-plugin/parsers.ts b/src/packages/v2-plugin/parsers.ts index bbbf5a8..031b1d1 100644 --- a/src/packages/v2-plugin/parsers.ts +++ b/src/packages/v2-plugin/parsers.ts @@ -5,6 +5,8 @@ import { parsers as babelParsers } from 'prettier/parser-babel'; import { parsers as htmlParsers } from 'prettier/parser-html'; import { parsers as typescriptParsers } from 'prettier/parser-typescript'; +const EOL = '\n'; + const addon = { parseBabel: (text: string, options: ParserOptions) => babelParsers.babel.parse(text, { babel: babelParsers.babel }, options), @@ -25,6 +27,34 @@ function transformParser( parsers: { [parserName: string]: Parser }, options: ParserOptions & ThisPluginOptions, ): FormattedTextAST => { + if (options.parentParser === 'markdown' || options.parentParser === 'mdx') { + let codeblockStart = '```'; + const codeblockEnd = '```'; + + if (options.parser === 'babel') { + codeblockStart = '```jsx'; + } else if (options.parser === 'typescript') { + codeblockStart = '```tsx'; + } + + const formattedCodeblock = format(`${codeblockStart}${EOL}${text}${EOL}${codeblockEnd}`, { + ...options, + plugins: [], + rangeEnd: Infinity, + endOfLine: 'lf', + parser: options.parentParser, + parentParser: undefined, + }); + const formattedText = formattedCodeblock + .trim() + .slice(`${codeblockStart}${EOL}`.length, -`${EOL}${codeblockEnd}`.length); + + return { + type: 'FormattedText', + body: formattedText, + }; + } + const plugins = options.plugins.filter((plugin) => typeof plugin !== 'string') as Plugin[]; let languageImplementedPlugin: Plugin | undefined; diff --git a/src/packages/v3-plugin/parsers.ts b/src/packages/v3-plugin/parsers.ts index 15d9583..a8a74df 100644 --- a/src/packages/v3-plugin/parsers.ts +++ b/src/packages/v3-plugin/parsers.ts @@ -5,6 +5,8 @@ import { parsers as babelParsers } from 'prettier/plugins/babel'; import { parsers as htmlParsers } from 'prettier/plugins/html'; import { parsers as typescriptParsers } from 'prettier/plugins/typescript'; +const EOL = '\n'; + const addon = { parseBabel: (text: string, options: ParserOptions) => babelParsers.babel.parse(text, options), parseTypescript: (text: string, options: ParserOptions) => @@ -23,6 +25,37 @@ function transformParser( text: string, options: ParserOptions & ThisPluginOptions, ): Promise => { + if (options.parentParser === 'markdown' || options.parentParser === 'mdx') { + let codeblockStart = '```'; + const codeblockEnd = '```'; + + if (options.parser === 'babel') { + codeblockStart = '```jsx'; + } else if (options.parser === 'typescript') { + codeblockStart = '```tsx'; + } + + const formattedCodeblock = await format( + `${codeblockStart}${EOL}${text}${EOL}${codeblockEnd}`, + { + ...options, + plugins: [], + rangeEnd: Infinity, + endOfLine: 'lf', + parser: options.parentParser, + parentParser: undefined, + }, + ); + const formattedText = formattedCodeblock + .trim() + .slice(`${codeblockStart}${EOL}`.length, -`${EOL}${codeblockEnd}`.length); + + return { + type: 'FormattedText', + body: formattedText, + }; + } + const plugins = options.plugins.filter((plugin) => typeof plugin !== 'string') as Plugin[]; let languageImplementedPlugin: Plugin | undefined; diff --git a/tests/v2-test/markdown/issue-80/__snapshots__/absolute.test.ts.snap b/tests/v2-test/markdown/issue-80/__snapshots__/absolute.test.ts.snap new file mode 100644 index 0000000..202dfe3 --- /dev/null +++ b/tests/v2-test/markdown/issue-80/__snapshots__/absolute.test.ts.snap @@ -0,0 +1,59 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`'(1) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +
+\`\`\` +" +`; + +exports[`'(2) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(3) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; + +exports[`'(4) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +
+\`\`\` +" +`; + +exports[`'(5) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(6) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; diff --git a/tests/v2-test/markdown/issue-80/__snapshots__/ideal.test.ts.snap b/tests/v2-test/markdown/issue-80/__snapshots__/ideal.test.ts.snap new file mode 100644 index 0000000..202dfe3 --- /dev/null +++ b/tests/v2-test/markdown/issue-80/__snapshots__/ideal.test.ts.snap @@ -0,0 +1,59 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`'(1) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +
+\`\`\` +" +`; + +exports[`'(2) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(3) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; + +exports[`'(4) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +
+\`\`\` +" +`; + +exports[`'(5) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(6) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; diff --git a/tests/v2-test/markdown/issue-80/__snapshots__/relative.test.ts.snap b/tests/v2-test/markdown/issue-80/__snapshots__/relative.test.ts.snap new file mode 100644 index 0000000..202dfe3 --- /dev/null +++ b/tests/v2-test/markdown/issue-80/__snapshots__/relative.test.ts.snap @@ -0,0 +1,59 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`'(1) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +
+\`\`\` +" +`; + +exports[`'(2) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(3) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; + +exports[`'(4) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +
+\`\`\` +" +`; + +exports[`'(5) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(6) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; diff --git a/tests/v2-test/markdown/issue-80/absolute.test.ts b/tests/v2-test/markdown/issue-80/absolute.test.ts new file mode 100644 index 0000000..4d24923 --- /dev/null +++ b/tests/v2-test/markdown/issue-80/absolute.test.ts @@ -0,0 +1,13 @@ +import { baseOptions } from 'test-settings'; + +import { thisPlugin, testSnapshotEach } from '../../adaptor'; +import { fixtures } from './fixtures'; + +const options = { + ...baseOptions, + plugins: [thisPlugin], + parser: 'markdown', + endingPosition: 'absolute', +}; + +testSnapshotEach(fixtures, options); diff --git a/tests/v2-test/markdown/issue-80/fixtures.ts b/tests/v2-test/markdown/issue-80/fixtures.ts new file mode 100644 index 0000000..e770ddb --- /dev/null +++ b/tests/v2-test/markdown/issue-80/fixtures.ts @@ -0,0 +1,78 @@ +import type { Fixture } from 'test-settings'; + +export const fixtures: Omit[] = [ + { + name: "(1) This plugin doesn't support markdown parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`jsx +
; +\`\`\` +`, + options: {}, + }, + { + name: "(2) This plugin doesn't support markdown parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`jsx +import foo from 'foo' + +
+\`\`\` +`, + options: {}, + }, + { + name: "(3) This plugin doesn't support markdown parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`jsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +`, + options: { + printWidth: 60, + }, + }, + { + name: "(4) This plugin doesn't support markdown parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`tsx +
; +\`\`\` +`, + options: {}, + }, + { + name: "(5) This plugin doesn't support markdown parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`tsx +import foo from 'foo' + +
+\`\`\` +`, + options: {}, + }, + { + name: "(6) This plugin doesn't support markdown parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`tsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +`, + options: { + printWidth: 60, + }, + }, +]; diff --git a/tests/v2-test/markdown/issue-80/ideal.test.ts b/tests/v2-test/markdown/issue-80/ideal.test.ts new file mode 100644 index 0000000..ff1b9d9 --- /dev/null +++ b/tests/v2-test/markdown/issue-80/ideal.test.ts @@ -0,0 +1,13 @@ +import { baseOptions } from 'test-settings'; + +import { thisPlugin, testSnapshotEach } from '../../adaptor'; +import { fixtures } from './fixtures'; + +const options = { + ...baseOptions, + plugins: [thisPlugin], + parser: 'markdown', + endingPosition: 'absolute-with-indent', +}; + +testSnapshotEach(fixtures, options); diff --git a/tests/v2-test/markdown/issue-80/relative.test.ts b/tests/v2-test/markdown/issue-80/relative.test.ts new file mode 100644 index 0000000..9ed61ed --- /dev/null +++ b/tests/v2-test/markdown/issue-80/relative.test.ts @@ -0,0 +1,13 @@ +import { baseOptions } from 'test-settings'; + +import { thisPlugin, testSnapshotEach } from '../../adaptor'; +import { fixtures } from './fixtures'; + +const options = { + ...baseOptions, + plugins: [thisPlugin], + parser: 'markdown', + endingPosition: 'relative', +}; + +testSnapshotEach(fixtures, options); diff --git a/tests/v2-test/mdx/issue-80/__snapshots__/absolute.test.ts.snap b/tests/v2-test/mdx/issue-80/__snapshots__/absolute.test.ts.snap new file mode 100644 index 0000000..e4f8f35 --- /dev/null +++ b/tests/v2-test/mdx/issue-80/__snapshots__/absolute.test.ts.snap @@ -0,0 +1,59 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`'(1) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +
+\`\`\` +" +`; + +exports[`'(2) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(3) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; + +exports[`'(4) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +
+\`\`\` +" +`; + +exports[`'(5) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(6) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; diff --git a/tests/v2-test/mdx/issue-80/__snapshots__/ideal.test.ts.snap b/tests/v2-test/mdx/issue-80/__snapshots__/ideal.test.ts.snap new file mode 100644 index 0000000..e4f8f35 --- /dev/null +++ b/tests/v2-test/mdx/issue-80/__snapshots__/ideal.test.ts.snap @@ -0,0 +1,59 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`'(1) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +
+\`\`\` +" +`; + +exports[`'(2) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(3) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; + +exports[`'(4) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +
+\`\`\` +" +`; + +exports[`'(5) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(6) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; diff --git a/tests/v2-test/mdx/issue-80/__snapshots__/relative.test.ts.snap b/tests/v2-test/mdx/issue-80/__snapshots__/relative.test.ts.snap new file mode 100644 index 0000000..e4f8f35 --- /dev/null +++ b/tests/v2-test/mdx/issue-80/__snapshots__/relative.test.ts.snap @@ -0,0 +1,59 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`'(1) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +
+\`\`\` +" +`; + +exports[`'(2) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(3) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; + +exports[`'(4) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +
+\`\`\` +" +`; + +exports[`'(5) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(6) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; diff --git a/tests/v2-test/mdx/issue-80/absolute.test.ts b/tests/v2-test/mdx/issue-80/absolute.test.ts new file mode 100644 index 0000000..1bbc1dd --- /dev/null +++ b/tests/v2-test/mdx/issue-80/absolute.test.ts @@ -0,0 +1,13 @@ +import { baseOptions } from 'test-settings'; + +import { thisPlugin, testSnapshotEach } from '../../adaptor'; +import { fixtures } from './fixtures'; + +const options = { + ...baseOptions, + plugins: [thisPlugin], + parser: 'mdx', + endingPosition: 'absolute', +}; + +testSnapshotEach(fixtures, options); diff --git a/tests/v2-test/mdx/issue-80/fixtures.ts b/tests/v2-test/mdx/issue-80/fixtures.ts new file mode 100644 index 0000000..9f5e6c0 --- /dev/null +++ b/tests/v2-test/mdx/issue-80/fixtures.ts @@ -0,0 +1,78 @@ +import type { Fixture } from 'test-settings'; + +export const fixtures: Omit[] = [ + { + name: "(1) This plugin doesn't support mdx parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`jsx +
; +\`\`\` +`, + options: {}, + }, + { + name: "(2) This plugin doesn't support mdx parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`jsx +import foo from 'foo' + +
+\`\`\` +`, + options: {}, + }, + { + name: "(3) This plugin doesn't support mdx parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`jsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +`, + options: { + printWidth: 60, + }, + }, + { + name: "(4) This plugin doesn't support mdx parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`tsx +
; +\`\`\` +`, + options: {}, + }, + { + name: "(5) This plugin doesn't support mdx parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`tsx +import foo from 'foo' + +
+\`\`\` +`, + options: {}, + }, + { + name: "(6) This plugin doesn't support mdx parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`tsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +`, + options: { + printWidth: 60, + }, + }, +]; diff --git a/tests/v2-test/mdx/issue-80/ideal.test.ts b/tests/v2-test/mdx/issue-80/ideal.test.ts new file mode 100644 index 0000000..bc69289 --- /dev/null +++ b/tests/v2-test/mdx/issue-80/ideal.test.ts @@ -0,0 +1,13 @@ +import { baseOptions } from 'test-settings'; + +import { thisPlugin, testSnapshotEach } from '../../adaptor'; +import { fixtures } from './fixtures'; + +const options = { + ...baseOptions, + plugins: [thisPlugin], + parser: 'mdx', + endingPosition: 'absolute-with-indent', +}; + +testSnapshotEach(fixtures, options); diff --git a/tests/v2-test/mdx/issue-80/relative.test.ts b/tests/v2-test/mdx/issue-80/relative.test.ts new file mode 100644 index 0000000..9360e62 --- /dev/null +++ b/tests/v2-test/mdx/issue-80/relative.test.ts @@ -0,0 +1,13 @@ +import { baseOptions } from 'test-settings'; + +import { thisPlugin, testSnapshotEach } from '../../adaptor'; +import { fixtures } from './fixtures'; + +const options = { + ...baseOptions, + plugins: [thisPlugin], + parser: 'mdx', + endingPosition: 'relative', +}; + +testSnapshotEach(fixtures, options); diff --git a/tests/v3-test/markdown/issue-80/__snapshots__/absolute.test.ts.snap b/tests/v3-test/markdown/issue-80/__snapshots__/absolute.test.ts.snap new file mode 100644 index 0000000..202dfe3 --- /dev/null +++ b/tests/v3-test/markdown/issue-80/__snapshots__/absolute.test.ts.snap @@ -0,0 +1,59 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`'(1) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +
+\`\`\` +" +`; + +exports[`'(2) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(3) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; + +exports[`'(4) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +
+\`\`\` +" +`; + +exports[`'(5) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(6) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; diff --git a/tests/v3-test/markdown/issue-80/__snapshots__/ideal.test.ts.snap b/tests/v3-test/markdown/issue-80/__snapshots__/ideal.test.ts.snap new file mode 100644 index 0000000..202dfe3 --- /dev/null +++ b/tests/v3-test/markdown/issue-80/__snapshots__/ideal.test.ts.snap @@ -0,0 +1,59 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`'(1) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +
+\`\`\` +" +`; + +exports[`'(2) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(3) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; + +exports[`'(4) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +
+\`\`\` +" +`; + +exports[`'(5) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(6) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; diff --git a/tests/v3-test/markdown/issue-80/__snapshots__/relative.test.ts.snap b/tests/v3-test/markdown/issue-80/__snapshots__/relative.test.ts.snap new file mode 100644 index 0000000..202dfe3 --- /dev/null +++ b/tests/v3-test/markdown/issue-80/__snapshots__/relative.test.ts.snap @@ -0,0 +1,59 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`'(1) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +
+\`\`\` +" +`; + +exports[`'(2) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(3) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; + +exports[`'(4) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +
+\`\`\` +" +`; + +exports[`'(5) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(6) This plugin doesn\\'t support markdown parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; diff --git a/tests/v3-test/markdown/issue-80/absolute.test.ts b/tests/v3-test/markdown/issue-80/absolute.test.ts new file mode 100644 index 0000000..4d24923 --- /dev/null +++ b/tests/v3-test/markdown/issue-80/absolute.test.ts @@ -0,0 +1,13 @@ +import { baseOptions } from 'test-settings'; + +import { thisPlugin, testSnapshotEach } from '../../adaptor'; +import { fixtures } from './fixtures'; + +const options = { + ...baseOptions, + plugins: [thisPlugin], + parser: 'markdown', + endingPosition: 'absolute', +}; + +testSnapshotEach(fixtures, options); diff --git a/tests/v3-test/markdown/issue-80/fixtures.ts b/tests/v3-test/markdown/issue-80/fixtures.ts new file mode 100644 index 0000000..e770ddb --- /dev/null +++ b/tests/v3-test/markdown/issue-80/fixtures.ts @@ -0,0 +1,78 @@ +import type { Fixture } from 'test-settings'; + +export const fixtures: Omit[] = [ + { + name: "(1) This plugin doesn't support markdown parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`jsx +
; +\`\`\` +`, + options: {}, + }, + { + name: "(2) This plugin doesn't support markdown parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`jsx +import foo from 'foo' + +
+\`\`\` +`, + options: {}, + }, + { + name: "(3) This plugin doesn't support markdown parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`jsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +`, + options: { + printWidth: 60, + }, + }, + { + name: "(4) This plugin doesn't support markdown parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`tsx +
; +\`\`\` +`, + options: {}, + }, + { + name: "(5) This plugin doesn't support markdown parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`tsx +import foo from 'foo' + +
+\`\`\` +`, + options: {}, + }, + { + name: "(6) This plugin doesn't support markdown parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`tsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +`, + options: { + printWidth: 60, + }, + }, +]; diff --git a/tests/v3-test/markdown/issue-80/ideal.test.ts b/tests/v3-test/markdown/issue-80/ideal.test.ts new file mode 100644 index 0000000..ff1b9d9 --- /dev/null +++ b/tests/v3-test/markdown/issue-80/ideal.test.ts @@ -0,0 +1,13 @@ +import { baseOptions } from 'test-settings'; + +import { thisPlugin, testSnapshotEach } from '../../adaptor'; +import { fixtures } from './fixtures'; + +const options = { + ...baseOptions, + plugins: [thisPlugin], + parser: 'markdown', + endingPosition: 'absolute-with-indent', +}; + +testSnapshotEach(fixtures, options); diff --git a/tests/v3-test/markdown/issue-80/relative.test.ts b/tests/v3-test/markdown/issue-80/relative.test.ts new file mode 100644 index 0000000..9ed61ed --- /dev/null +++ b/tests/v3-test/markdown/issue-80/relative.test.ts @@ -0,0 +1,13 @@ +import { baseOptions } from 'test-settings'; + +import { thisPlugin, testSnapshotEach } from '../../adaptor'; +import { fixtures } from './fixtures'; + +const options = { + ...baseOptions, + plugins: [thisPlugin], + parser: 'markdown', + endingPosition: 'relative', +}; + +testSnapshotEach(fixtures, options); diff --git a/tests/v3-test/mdx/issue-80/__snapshots__/absolute.test.ts.snap b/tests/v3-test/mdx/issue-80/__snapshots__/absolute.test.ts.snap new file mode 100644 index 0000000..e4f8f35 --- /dev/null +++ b/tests/v3-test/mdx/issue-80/__snapshots__/absolute.test.ts.snap @@ -0,0 +1,59 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`'(1) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +
+\`\`\` +" +`; + +exports[`'(2) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(3) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; + +exports[`'(4) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +
+\`\`\` +" +`; + +exports[`'(5) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(6) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; diff --git a/tests/v3-test/mdx/issue-80/__snapshots__/ideal.test.ts.snap b/tests/v3-test/mdx/issue-80/__snapshots__/ideal.test.ts.snap new file mode 100644 index 0000000..e4f8f35 --- /dev/null +++ b/tests/v3-test/mdx/issue-80/__snapshots__/ideal.test.ts.snap @@ -0,0 +1,59 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`'(1) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +
+\`\`\` +" +`; + +exports[`'(2) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(3) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; + +exports[`'(4) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +
+\`\`\` +" +`; + +exports[`'(5) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(6) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; diff --git a/tests/v3-test/mdx/issue-80/__snapshots__/relative.test.ts.snap b/tests/v3-test/mdx/issue-80/__snapshots__/relative.test.ts.snap new file mode 100644 index 0000000..e4f8f35 --- /dev/null +++ b/tests/v3-test/mdx/issue-80/__snapshots__/relative.test.ts.snap @@ -0,0 +1,59 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`'(1) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +
+\`\`\` +" +`; + +exports[`'(2) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(3) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`jsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; + +exports[`'(4) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +
+\`\`\` +" +`; + +exports[`'(5) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +import foo from "foo"; + +
; +\`\`\` +" +`; + +exports[`'(6) This plugin doesn\\'t support mdx parser, so it leaves Prettier\\'s output as is.' > expectation 1`] = ` +"\`\`\`tsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +" +`; diff --git a/tests/v3-test/mdx/issue-80/absolute.test.ts b/tests/v3-test/mdx/issue-80/absolute.test.ts new file mode 100644 index 0000000..1bbc1dd --- /dev/null +++ b/tests/v3-test/mdx/issue-80/absolute.test.ts @@ -0,0 +1,13 @@ +import { baseOptions } from 'test-settings'; + +import { thisPlugin, testSnapshotEach } from '../../adaptor'; +import { fixtures } from './fixtures'; + +const options = { + ...baseOptions, + plugins: [thisPlugin], + parser: 'mdx', + endingPosition: 'absolute', +}; + +testSnapshotEach(fixtures, options); diff --git a/tests/v3-test/mdx/issue-80/fixtures.ts b/tests/v3-test/mdx/issue-80/fixtures.ts new file mode 100644 index 0000000..9f5e6c0 --- /dev/null +++ b/tests/v3-test/mdx/issue-80/fixtures.ts @@ -0,0 +1,78 @@ +import type { Fixture } from 'test-settings'; + +export const fixtures: Omit[] = [ + { + name: "(1) This plugin doesn't support mdx parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`jsx +
; +\`\`\` +`, + options: {}, + }, + { + name: "(2) This plugin doesn't support mdx parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`jsx +import foo from 'foo' + +
+\`\`\` +`, + options: {}, + }, + { + name: "(3) This plugin doesn't support mdx parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`jsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +`, + options: { + printWidth: 60, + }, + }, + { + name: "(4) This plugin doesn't support mdx parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`tsx +
; +\`\`\` +`, + options: {}, + }, + { + name: "(5) This plugin doesn't support mdx parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`tsx +import foo from 'foo' + +
+\`\`\` +`, + options: {}, + }, + { + name: "(6) This plugin doesn't support mdx parser, so it leaves Prettier's output as is.", + input: ` +\`\`\`tsx +export function Foo({ children }) { + return ( +
+ {children} +
+ ); +} +\`\`\` +`, + options: { + printWidth: 60, + }, + }, +]; diff --git a/tests/v3-test/mdx/issue-80/ideal.test.ts b/tests/v3-test/mdx/issue-80/ideal.test.ts new file mode 100644 index 0000000..bc69289 --- /dev/null +++ b/tests/v3-test/mdx/issue-80/ideal.test.ts @@ -0,0 +1,13 @@ +import { baseOptions } from 'test-settings'; + +import { thisPlugin, testSnapshotEach } from '../../adaptor'; +import { fixtures } from './fixtures'; + +const options = { + ...baseOptions, + plugins: [thisPlugin], + parser: 'mdx', + endingPosition: 'absolute-with-indent', +}; + +testSnapshotEach(fixtures, options); diff --git a/tests/v3-test/mdx/issue-80/relative.test.ts b/tests/v3-test/mdx/issue-80/relative.test.ts new file mode 100644 index 0000000..9360e62 --- /dev/null +++ b/tests/v3-test/mdx/issue-80/relative.test.ts @@ -0,0 +1,13 @@ +import { baseOptions } from 'test-settings'; + +import { thisPlugin, testSnapshotEach } from '../../adaptor'; +import { fixtures } from './fixtures'; + +const options = { + ...baseOptions, + plugins: [thisPlugin], + parser: 'mdx', + endingPosition: 'relative', +}; + +testSnapshotEach(fixtures, options);