Skip to content

Commit 04037c2

Browse files
committed
Create an example of autoimports not working
1 parent 0a01042 commit 04037c2

5 files changed

Lines changed: 47 additions & 9 deletions

File tree

‎.vscode/launch.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"--skip-release-notes",
1515
"--skip-welcome",
1616
"--extensionDevelopmentPath=${workspaceFolder}/vscode",
17-
"${workspaceFolder}/fixtures.code-workspace"
17+
"${workspaceFolder}/examples/autoimport-issue"
1818
],
1919
"env": {
2020
"NODE_OPTIONS": "--enable-source-maps"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {} from './lib'
2+
3+
{AAAAA}

‎examples/autoimport-issue/lib.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const AAAAAAAAAAAAAAAAAAA = ''
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"checkJs": true,
4+
"noEmit": true,
5+
"jsx": "react-jsx",
6+
"lib": ["esnext"]
7+
},
8+
"contentMappers": [
9+
{
10+
"package": "mdx-content-mapper",
11+
"extensions": [".mdx"]
12+
}
13+
]
14+
}

‎lib/requests/transform.js‎

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
* @import { Scope } from 'estree-util-scope'
1010
* @import { Nodes } from 'mdast'
1111
* @import { MdxjsEsm } from 'mdast-util-mdxjs-esm'
12-
* @import { MappedOutput, SpanMapping, TransformParams, TransformResult } from '../protocol.js'
12+
* @import {
13+
* MappedOutput,
14+
* SpanMapFeature,
15+
* SpanMapKind,
16+
* SpanMapping,
17+
* TransformParams,
18+
* TransformResult
19+
* } from '../protocol.js'
1320
* @import { Project } from '../util/projects.js'
1421
*/
1522

@@ -222,8 +229,24 @@ export function transformActual(params, project) {
222229
providerImportSource
223230
)
224231

232+
/**
233+
* The Volar mapping that maps all ESM syntax of the MDX file to the virtual JavaScript file.
234+
*
235+
* @type {SpanMapping[]}
236+
*/
237+
const esmMappings = []
225238
let hasAwait = false
226239
let esm = checkMdx ? '// @ts-check\n' : ''
240+
241+
esmMappings.push([
242+
0,
243+
0,
244+
esm.length,
245+
0,
246+
/** @satisfies {SpanMapKind.Verbatim} */ (0),
247+
/** @satisfies {SpanMapFeature.AutoInsert} */ (131_072)
248+
])
249+
227250
let jsx = ''
228251
let jsxVariables = ''
229252

@@ -251,13 +274,6 @@ export function transformActual(params, project) {
251274
/** @type {MappedOutput[] | undefined} */
252275
let supplemental
253276

254-
/**
255-
* The Volar mapping that maps all ESM syntax of the MDX file to the virtual JavaScript file.
256-
*
257-
* @type {SpanMapping[]}
258-
*/
259-
const esmMappings = []
260-
261277
/**
262278
* The Volar mapping that maps all JSX syntax of the MDX file to the virtual JavaScript file.
263279
*
@@ -794,6 +810,10 @@ export function transformActual(params, project) {
794810
padOffsets(jsxVariablesMapping, esm.length)
795811
esm += jsxVariables
796812

813+
console.error('-'.repeat(100))
814+
console.error(esm)
815+
console.error('-'.repeat(100))
816+
797817
return {
798818
text: esm,
799819
extension: '.jsx',

0 commit comments

Comments
 (0)