Skip to content

Commit

Permalink
Update for changes in deep types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 30, 2021
1 parent c3502d1 commit fc5f7d3
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 22 deletions.
5 changes: 3 additions & 2 deletions lib/integration/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ export function esbuild(options = {}) {
value = file.value
messages = file.messages
} catch (error) {
error.fatal = true
messages.push(error)
const exception = /** @type {VFileMessage} */ (error)
exception.fatal = true
messages.push(exception)
}

for (const message of messages) {
Expand Down
8 changes: 6 additions & 2 deletions lib/integration/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ export function rollup(options = {}) {

return {
name: 'xdm',
// @ts-expect-error `map` is added if a `SourceMapGenerator` is passed in.
async transform(value, path) {
const file = new VFile({value, path})

if (filter(file.path) && extnames.includes(file.extname)) {
if (
file.extname &&
filter(file.path) &&
extnames.includes(file.extname)
) {
const compiled = await process(file)
// @ts-expect-error `map` is added if a `SourceMapGenerator` is passed in.
return {code: String(compiled.value), map: compiled.map}
// V8 on Erbium.
/* c8 ignore next 2 */
Expand Down
1 change: 0 additions & 1 deletion lib/plugin/recma-stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export function recmaStringify(options = {}) {
})

if (sourceMap) {
// @ts-expect-error custom source map.
file.map = sourceMap.toJSON()
}

Expand Down
2 changes: 1 addition & 1 deletion lib/util/resolve-file-and-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function resolveFileAndOptions(vfileCompatible, options) {
format:
format === 'md' || format === 'mdx'
? format
: (rest.mdExtensions || md).includes(file.extname)
: file.extname && (rest.mdExtensions || md).includes(file.extname)
? 'md'
: 'mdx',
...rest
Expand Down
30 changes: 18 additions & 12 deletions test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,10 @@ test('xdm', async (t) => {
)
)
t.fail()
} catch (error) {
} catch (/** @type {unknown} */ error) {
const exception = /** @type {Error} */ (error)
t.match(
error.message,
exception.message,
/Element type is invalid/,
'should throw on missing components in exported components'
)
Expand Down Expand Up @@ -420,9 +421,10 @@ test('xdm', async (t) => {
React.createElement(await run(compileSync('export default a')))
)
t.fail()
} catch (error) {
} catch (/** @type {unknown} */ error) {
const exception = /** @type {Error} */ (error)
t.equal(
error.message,
exception.message,
'a is not defined',
'should support an identifier as an export default'
)
Expand All @@ -433,9 +435,10 @@ test('xdm', async (t) => {
try {
renderToStaticMarkup(React.createElement(await run(compileSync('<X />'))))
t.fail()
} catch (error) {
} catch (/** @type {unknown} */ error) {
const exception = /** @type {Error} */ (error)
t.match(
error.message,
exception.message,
/Element type is invalid/,
'should throw if a required component is not passed'
)
Expand All @@ -444,9 +447,10 @@ test('xdm', async (t) => {
try {
renderToStaticMarkup(React.createElement(await run(compileSync('<a.b />'))))
t.fail()
} catch (error) {
} catch (/** @type {unknown} */ error) {
const exception = /** @type {Error} */ (error)
t.equal(
error.message,
exception.message,
"Cannot read property 'b' of undefined",
'should throw if a required member is not passed'
)
Expand Down Expand Up @@ -484,9 +488,10 @@ test('xdm', async (t) => {
)
)
t.fail()
} catch (error) {
} catch (/** @type {unknown} */ error) {
const exception = /** @type {Error} */ (error)
t.match(
error.message,
exception.message,
/Element type is invalid/,
'should throw if a required component is not passed or given to `MDXProvider`'
)
Expand Down Expand Up @@ -524,9 +529,10 @@ test('xdm', async (t) => {
// @ts-expect-error runtime.
createProcessor({format: 'detect'})
t.fail()
} catch (error) {
} catch (/** @type {unknown} */ error) {
const exception = /** @type {Error} */ (error)
t.equal(
error.message,
exception.message,
"Incorrect `format: 'detect'`: `createProcessor` can support either `md` or `mdx`; it does not support detecting the format",
'should not support `format: detect`'
)
Expand Down
3 changes: 2 additions & 1 deletion test/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ test('xdm (esbuild)', async (t) => {
})
t.fail('esbuild should throw')
} catch (error) {
const message = error.errors[0]
const exception = /** @type {BuildFailure} */ (error)
const message = exception.errors[0]
delete message.detail
t.deepEqual(
message,
Expand Down
3 changes: 2 additions & 1 deletion test/esm-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ test('xdm (ESM loader)', async (t) => {
/* @ts-expect-error file is dynamically generated */
Content = (await import('./context/esm-loader.mdx')).default // type-coverage:ignore-line
} catch (error) {
if (error.code === 'ERR_UNKNOWN_FILE_EXTENSION') {
const exception = /** @type {NodeJS.ErrnoException} */ (error)
if (exception.code === 'ERR_UNKNOWN_FILE_EXTENSION') {
await fs.unlink(path.join(base, 'esm-loader.mdx'))
throw new Error(
'Please run Node with `--experimental-loader=./esm-loader.js` to test the ESM loader'
Expand Down
4 changes: 2 additions & 2 deletions test/source-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ test('xdm (source maps)', async (t) => {

file.value +=
'\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,' +
// @ts-expect-error: source map.
Buffer.from(JSON.stringify(file.map)).toString('base64') +
'\n'

Expand All @@ -45,7 +44,8 @@ test('xdm (source maps)', async (t) => {
renderToStaticMarkup(React.createElement(Content))
t.fail()
} catch (error) {
const match = /at Component \(file:([^)]+)\)/.exec(error.stack)
const exception = /** @type {Error} */ (error)
const match = /at Component \(file:([^)]+)\)/.exec(String(exception.stack))
const place =
path.posix.join(...base.split(path.sep), 'unknown.mdx') + ':2:3'

Expand Down

0 comments on commit fc5f7d3

Please sign in to comment.