Socket
Socket
Sign inDemoInstall

micromark-extension-mdxjs-esm

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micromark-extension-mdxjs-esm - npm Package Compare versions

Comparing version 2.0.1 to 3.0.0

44

dev/lib/syntax.d.ts

@@ -10,9 +10,9 @@ /**

*/
export function mdxjsEsm(options: Options): Extension
export type Acorn = import('micromark-util-events-to-acorn').Acorn
export type AcornOptions = import('micromark-util-events-to-acorn').AcornOptions
export type Extension = import('micromark-util-types').Extension
export type State = import('micromark-util-types').State
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Tokenizer = import('micromark-util-types').Tokenizer
export function mdxjsEsm(options: Options): Extension;
export type Acorn = import('micromark-util-events-to-acorn').Acorn;
export type AcornOptions = import('micromark-util-events-to-acorn').AcornOptions;
export type Extension = import('micromark-util-types').Extension;
export type State = import('micromark-util-types').State;
export type TokenizeContext = import('micromark-util-types').TokenizeContext;
export type Tokenizer = import('micromark-util-types').Tokenizer;
/**

@@ -22,16 +22,16 @@ * Configuration (required).

export type Options = {
/**
* Acorn parser to use (required).
*/
acorn: Acorn
/**
* Configuration for acorn (default: `{ecmaVersion: 2020, locations: true,
* sourceType: 'module'}`); all fields except `locations` can be set.
*/
acornOptions?: AcornOptions | null | undefined
/**
* Whether to add `estree` fields to tokens with results from acorn
* (default: `false`).
*/
addResult?: boolean | null | undefined
}
/**
* Acorn parser to use (required).
*/
acorn: Acorn;
/**
* Configuration for acorn (default: `{ecmaVersion: 2024, locations: true,
* sourceType: 'module'}`); all fields except `locations` can be set.
*/
acornOptions?: AcornOptions | null | undefined;
/**
* Whether to add `estree` fields to tokens with results from acorn
* (default: `false`).
*/
addResult?: boolean | null | undefined;
};

@@ -16,3 +16,3 @@ /**

* @property {AcornOptions | null | undefined} [acornOptions]
* Configuration for acorn (default: `{ecmaVersion: 2020, locations: true,
* Configuration for acorn (default: `{ecmaVersion: 2024, locations: true,
* sourceType: 'module'}`); all fields except `locations` can be set.

@@ -61,4 +61,5 @@ * @property {boolean | null | undefined} [addResult=false]

const acornOptions = Object.assign(
{ecmaVersion: 2020, sourceType: 'module'},
options.acornOptions
{ecmaVersion: 2024, sourceType: 'module'},
options.acornOptions,
{locations: true}
)

@@ -65,0 +66,0 @@

// Note: more types exposed from `index.d.ts`.
export {mdxjsEsm} from './lib/syntax.js'
export { mdxjsEsm } from './lib/syntax.js';

@@ -10,9 +10,9 @@ /**

*/
export function mdxjsEsm(options: Options): Extension
export type Acorn = import('micromark-util-events-to-acorn').Acorn
export type AcornOptions = import('micromark-util-events-to-acorn').AcornOptions
export type Extension = import('micromark-util-types').Extension
export type State = import('micromark-util-types').State
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Tokenizer = import('micromark-util-types').Tokenizer
export function mdxjsEsm(options: Options): Extension;
export type Acorn = import('micromark-util-events-to-acorn').Acorn;
export type AcornOptions = import('micromark-util-events-to-acorn').AcornOptions;
export type Extension = import('micromark-util-types').Extension;
export type State = import('micromark-util-types').State;
export type TokenizeContext = import('micromark-util-types').TokenizeContext;
export type Tokenizer = import('micromark-util-types').Tokenizer;
/**

@@ -22,16 +22,16 @@ * Configuration (required).

export type Options = {
/**
* Acorn parser to use (required).
*/
acorn: Acorn
/**
* Configuration for acorn (default: `{ecmaVersion: 2020, locations: true,
* sourceType: 'module'}`); all fields except `locations` can be set.
*/
acornOptions?: AcornOptions | null | undefined
/**
* Whether to add `estree` fields to tokens with results from acorn
* (default: `false`).
*/
addResult?: boolean | null | undefined
}
/**
* Acorn parser to use (required).
*/
acorn: Acorn;
/**
* Configuration for acorn (default: `{ecmaVersion: 2024, locations: true,
* sourceType: 'module'}`); all fields except `locations` can be set.
*/
acornOptions?: AcornOptions | null | undefined;
/**
* Whether to add `estree` fields to tokens with results from acorn
* (default: `false`).
*/
addResult?: boolean | null | undefined;
};

@@ -16,3 +16,3 @@ /**

* @property {AcornOptions | null | undefined} [acornOptions]
* Configuration for acorn (default: `{ecmaVersion: 2020, locations: true,
* Configuration for acorn (default: `{ecmaVersion: 2024, locations: true,
* sourceType: 'module'}`); all fields except `locations` can be set.

@@ -24,18 +24,13 @@ * @property {boolean | null | undefined} [addResult=false]

import {blankLine} from 'micromark-core-commonmark'
import {asciiAlpha, markdownLineEnding} from 'micromark-util-character'
import {eventsToAcorn} from 'micromark-util-events-to-acorn'
import {positionFromEstree} from 'unist-util-position-from-estree'
import {VFileMessage} from 'vfile-message'
import { blankLine } from 'micromark-core-commonmark';
import { asciiAlpha, markdownLineEnding } from 'micromark-util-character';
import { eventsToAcorn } from 'micromark-util-events-to-acorn';
import { positionFromEstree } from 'unist-util-position-from-estree';
import { VFileMessage } from 'vfile-message';
const blankLineBefore = {
tokenize: tokenizeNextBlank,
partial: true
}
const trouble = 'https://github.com/micromark/micromark-extension-mdxjs-esm'
const allowedAcornTypes = new Set([
'ExportAllDeclaration',
'ExportDefaultDeclaration',
'ExportNamedDeclaration',
'ImportDeclaration'
])
};
const trouble = 'https://github.com/micromark/micromark-extension-mdxjs-esm';
const allowedAcornTypes = new Set(['ExportAllDeclaration', 'ExportDefaultDeclaration', 'ExportNamedDeclaration', 'ImportDeclaration']);

@@ -55,14 +50,13 @@ /**

concrete: true
}
};
if (!options || !options.acorn || !options.acorn.parse) {
throw new Error('Expected an `acorn` instance passed in as `options.acorn`')
throw new Error('Expected an `acorn` instance passed in as `options.acorn`');
}
const acorn = options.acorn
const acornOptions = Object.assign(
{
ecmaVersion: 2020,
sourceType: 'module'
},
options.acornOptions
)
const acorn = options.acorn;
const acornOptions = Object.assign({
ecmaVersion: 2024,
sourceType: 'module'
}, options.acornOptions, {
locations: true
});
return {

@@ -73,3 +67,3 @@ flow: {

}
}
};

@@ -81,9 +75,7 @@ /**

function tokenizeExportImport(effects, ok, nok) {
const self = this
const definedModuleSpecifiers =
self.parser.definedModuleSpecifiers ||
(self.parser.definedModuleSpecifiers = [])
const eventStart = this.events.length + 1 // Add the main `mdxjsEsm` token
let buffer = ''
return self.interrupt ? nok : start
const self = this;
const definedModuleSpecifiers = self.parser.definedModuleSpecifiers || (self.parser.definedModuleSpecifiers = []);
const eventStart = this.events.length + 1; // Add the main `mdxjsEsm` token
let buffer = '';
return self.interrupt ? nok : start;

@@ -102,9 +94,9 @@ /**

// Only at the start of a line, not at whitespace or in a container.
if (self.now().column > 1) return nok(code)
effects.enter('mdxjsEsm')
effects.enter('mdxjsEsmData')
effects.consume(code)
if (self.now().column > 1) return nok(code);
effects.enter('mdxjsEsm');
effects.enter('mdxjsEsmData');
effects.consume(code);
// eslint-disable-next-line unicorn/prefer-code-point
buffer += String.fromCharCode(code)
return word
buffer += String.fromCharCode(code);
return word;
}

@@ -124,13 +116,13 @@

if (asciiAlpha(code)) {
effects.consume(code)
effects.consume(code);
// @ts-expect-error: definitely a number.
// eslint-disable-next-line unicorn/prefer-code-point
buffer += String.fromCharCode(code)
return word
buffer += String.fromCharCode(code);
return word;
}
if ((buffer === 'import' || buffer === 'export') && code === 32) {
effects.consume(code)
return inside
effects.consume(code);
return inside;
}
return nok(code)
return nok(code);
}

@@ -150,7 +142,7 @@

if (code === null || markdownLineEnding(code)) {
effects.exit('mdxjsEsmData')
return lineStart(code)
effects.exit('mdxjsEsmData');
return lineStart(code);
}
effects.consume(code)
return inside
effects.consume(code);
return inside;
}

@@ -171,9 +163,9 @@

if (code === null) {
return atEnd(code)
return atEnd(code);
}
if (markdownLineEnding(code)) {
return effects.check(blankLineBefore, atEnd, continuationStart)(code)
return effects.check(blankLineBefore, atEnd, continuationStart)(code);
}
effects.enter('mdxjsEsmData')
return inside(code)
effects.enter('mdxjsEsmData');
return inside(code);
}

@@ -193,6 +185,6 @@

function continuationStart(code) {
effects.enter('lineEnding')
effects.consume(code)
effects.exit('lineEnding')
return lineStart
effects.enter("lineEnding");
effects.consume(code);
effects.exit("lineEnding");
return lineStart;
}

@@ -215,7 +207,4 @@

tokenTypes: ['mdxjsEsmData'],
prefix:
definedModuleSpecifiers.length > 0
? 'var ' + definedModuleSpecifiers.join(',') + '\n'
: ''
})
prefix: definedModuleSpecifiers.length > 0 ? 'var ' + definedModuleSpecifiers.join(',') + '\n' : ''
});
if (result.error) {

@@ -225,42 +214,32 @@ // There’s an error, which could be solved with more content, and there

if (code !== null && result.swallow) {
return continuationStart(code)
return continuationStart(code);
}
const error = new VFileMessage(
'Could not parse import/exports with acorn',
{
cause: result.error,
place: {
line: result.error.loc.line,
column: result.error.loc.column + 1,
offset: result.error.pos
},
ruleId: 'acorn',
source: 'micromark-extension-mdxjs-esm'
}
)
error.url = trouble + '#could-not-parse-importexports-with-acorn'
throw error
const error = new VFileMessage('Could not parse import/exports with acorn', {
cause: result.error,
place: {
line: result.error.loc.line,
column: result.error.loc.column + 1,
offset: result.error.pos
},
ruleId: 'acorn',
source: 'micromark-extension-mdxjs-esm'
});
error.url = trouble + '#could-not-parse-importexports-with-acorn';
throw error;
}
// Remove the `VariableDeclaration`.
if (definedModuleSpecifiers.length > 0) {
const declaration = result.estree.body.shift()
const declaration = result.estree.body.shift();
}
let index = -1
let index = -1;
while (++index < result.estree.body.length) {
const node = result.estree.body[index]
const node = result.estree.body[index];
if (!allowedAcornTypes.has(node.type)) {
const error = new VFileMessage(
'Unexpected `' +
node.type +
'` in code: only import/exports are supported',
{
place: positionFromEstree(node),
ruleId: 'non-esm',
source: 'micromark-extension-mdxjs-esm'
}
)
error.url =
trouble +
'#unexpected-type-in-code-only-importexports-are-supported'
throw error
const error = new VFileMessage('Unexpected `' + node.type + '` in code: only import/exports are supported', {
place: positionFromEstree(node),
ruleId: 'non-esm',
source: 'micromark-extension-mdxjs-esm'
});
error.url = trouble + '#unexpected-type-in-code-only-importexports-are-supported';
throw error;
}

@@ -272,18 +251,13 @@

if (node.type === 'ImportDeclaration' && !self.interrupt) {
let index = -1
let index = -1;
while (++index < node.specifiers.length) {
const specifier = node.specifiers[index]
definedModuleSpecifiers.push(specifier.local.name)
const specifier = node.specifiers[index];
definedModuleSpecifiers.push(specifier.local.name);
}
}
}
Object.assign(
effects.exit('mdxjsEsm'),
options.addResult
? {
estree: result.estree
}
: undefined
)
return ok(code)
Object.assign(effects.exit('mdxjsEsm'), options.addResult ? {
estree: result.estree
} : undefined);
return ok(code);
}

@@ -295,3 +269,3 @@ }

function tokenizeNextBlank(effects, ok, nok) {
return start
return start;

@@ -302,7 +276,7 @@ /**

function start(code) {
effects.enter('lineEndingBlank')
effects.consume(code)
effects.exit('lineEndingBlank')
return effects.attempt(blankLine, ok, nok)
effects.enter("lineEndingBlank");
effects.consume(code);
effects.exit("lineEndingBlank");
return effects.attempt(blankLine, ok, nok);
}
}
}
{
"name": "micromark-extension-mdxjs-esm",
"version": "2.0.1",
"version": "3.0.0",
"description": "micromark extension to support MDX JS import/exports",

@@ -61,3 +61,3 @@ "license": "MIT",

"micromark-build": "^2.0.0",
"prettier": "^2.0.0",
"prettier": "^3.0.0",
"remark-cli": "^11.0.0",

@@ -67,3 +67,3 @@ "remark-preset-wooorm": "^9.0.0",

"typescript": "^5.0.0",
"xo": "^0.54.0"
"xo": "^0.56.0"
},

@@ -73,3 +73,3 @@ "scripts": {

"build": "tsc --build --clean && tsc --build && type-coverage && micromark-build",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
"test-api-prod": "node --conditions production test/index.js",

@@ -76,0 +76,0 @@ "test-api-dev": "node --conditions development test/index.js",

@@ -142,3 +142,3 @@ # micromark-extension-mdxjs-esm

* `acornOptions` ([`AcornOptions`][acorn-options], default:
`{ecmaVersion: 2020, locations: true, sourceType: 'module'}`)
`{ecmaVersion: 2024, locations: true, sourceType: 'module'}`)
— configuration for acorn; all fields except `locations` can be set

@@ -145,0 +145,0 @@ * `addResult` (`boolean`, default: `false`)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc