Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

micromark-extension-mdx-expression

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micromark-extension-mdx-expression - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

readme.md

45

dev/lib/syntax.d.ts
/**
* @param {Options} options
* Add support for MDX expressions.
*
* Function called optionally with options to get a syntax extension for
* micromark.
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {Extension}
* Syntax extension for micromark (passed in `extensions`).
*/
export function mdxExpression(options?: Options): Extension
export function mdxExpression(options?: Options | null | undefined): Extension
export type Extension = import('micromark-util-types').Extension
export type Tokenizer = import('micromark-util-types').Tokenizer
export type State = import('micromark-util-types').State
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Acorn = import('micromark-util-events-to-acorn').Acorn
export type AcornOptions = import('micromark-util-events-to-acorn').AcornOptions
/**
* Configuration (optional).
*/
export type Options = {
addResult?: boolean | undefined
acorn?: import('micromark-util-events-to-acorn').Acorn | undefined
acornOptions?: import('acorn').Options | undefined
spread?: boolean | undefined
allowEmpty?: boolean | undefined
/**
* Acorn parser to use (optional).
*/
acorn?: Acorn | null | undefined
/**
* Options to pass to acorn (default: `{ecmaVersion: 2020, locations: true,
* sourceType: 'module'}`).
* All fields (except for `locations`) can be set.
*/
acornOptions?: AcornOptions | null | undefined
/**
* Whether to add an `estree` field to `mdxFlowExpression` and
* `mdxTextExpression` tokens with results from acorn.
*/
addResult?: boolean | null | undefined
/**
* Undocumented option to parse only a spread (used by
* `micromark-extension-mdx-jsx` to parse spread attributes).
*/
spread?: boolean | null | undefined
/**
* Undocumented option to disallow empty attributes (used by
* `micromark-extension-mdx-jsx` to prohobit empty attribute values).
*/
allowEmpty?: boolean | null | undefined
}

60

dev/lib/syntax.js

@@ -5,13 +5,23 @@ /**

* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-events-to-acorn').Acorn} Acorn
* @typedef {import('micromark-util-events-to-acorn').AcornOptions} AcornOptions
*/
/**
*
* @typedef Options
* @property {boolean} [addResult=false]
* @property {Acorn} [acorn]
* @property {AcornOptions} [acornOptions]
* @property {boolean} [spread=false]
* @property {boolean} [allowEmpty=true]
* Configuration (optional).
* @property {Acorn | null | undefined} [acorn]
* Acorn parser to use (optional).
* @property {AcornOptions | null | undefined} [acornOptions]
* Options to pass to acorn (default: `{ecmaVersion: 2020, locations: true,
* sourceType: 'module'}`).
* All fields (except for `locations`) can be set.
* @property {boolean | null | undefined} [addResult=false]
* Whether to add an `estree` field to `mdxFlowExpression` and
* `mdxTextExpression` tokens with results from acorn.
* @property {boolean | null | undefined} [spread=false]
* Undocumented option to parse only a spread (used by
* `micromark-extension-mdx-jsx` to parse spread attributes).
* @property {boolean | null | undefined} [allowEmpty=true]
* Undocumented option to disallow empty attributes (used by
* `micromark-extension-mdx-jsx` to prohobit empty attribute values).
*/

@@ -27,8 +37,16 @@

/**
* @param {Options} options
* Add support for MDX expressions.
*
* Function called optionally with options to get a syntax extension for
* micromark.
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {Extension}
* Syntax extension for micromark (passed in `extensions`).
*/
export function mdxExpression(options = {}) {
const addResult = options.addResult
const acorn = options.acorn
export function mdxExpression(options) {
const options_ = options || {}
const addResult = options_.addResult
const acorn = options_.acorn
// Hidden: `micromark-extension-mdx-jsx` supports expressions in tags,

@@ -39,4 +57,4 @@ // and one of them is only “spread” elements.

// to test that behavior.
const spread = options.spread
let allowEmpty = options.allowEmpty
const spread = options_.spread
let allowEmpty = options_.allowEmpty
/** @type {AcornOptions} */

@@ -58,5 +76,5 @@ let acornOptions

{ecmaVersion: 2020, sourceType: 'module'},
options.acornOptions
options_.acornOptions
)
} else if (options.acornOptions || options.addResult) {
} else if (options_.acornOptions || options_.addResult) {
throw new Error('Expected an `acorn` instance passed in as `options.acorn`')

@@ -72,3 +90,6 @@ }

/** @type {Tokenizer} */
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeFlowExpression(effects, ok, nok) {

@@ -105,3 +126,6 @@ const self = this

/** @type {Tokenizer} */
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeTextExpression(effects, ok) {

@@ -108,0 +132,0 @@ const self = this

/**
* @param {Options} options
* Add support for MDX expressions.
*
* Function called optionally with options to get a syntax extension for
* micromark.
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {Extension}
* Syntax extension for micromark (passed in `extensions`).
*/
export function mdxExpression(options?: Options): Extension
export function mdxExpression(options?: Options | null | undefined): Extension
export type Extension = import('micromark-util-types').Extension
export type Tokenizer = import('micromark-util-types').Tokenizer
export type State = import('micromark-util-types').State
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Acorn = import('micromark-util-events-to-acorn').Acorn
export type AcornOptions = import('micromark-util-events-to-acorn').AcornOptions
/**
* Configuration (optional).
*/
export type Options = {
addResult?: boolean | undefined
acorn?: import('micromark-util-events-to-acorn').Acorn | undefined
acornOptions?: import('acorn').Options | undefined
spread?: boolean | undefined
allowEmpty?: boolean | undefined
/**
* Acorn parser to use (optional).
*/
acorn?: Acorn | null | undefined
/**
* Options to pass to acorn (default: `{ecmaVersion: 2020, locations: true,
* sourceType: 'module'}`).
* All fields (except for `locations`) can be set.
*/
acornOptions?: AcornOptions | null | undefined
/**
* Whether to add an `estree` field to `mdxFlowExpression` and
* `mdxTextExpression` tokens with results from acorn.
*/
addResult?: boolean | null | undefined
/**
* Undocumented option to parse only a spread (used by
* `micromark-extension-mdx-jsx` to parse spread attributes).
*/
spread?: boolean | null | undefined
/**
* Undocumented option to disallow empty attributes (used by
* `micromark-extension-mdx-jsx` to prohobit empty attribute values).
*/
allowEmpty?: boolean | null | undefined
}

@@ -5,25 +5,44 @@ /**

* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-events-to-acorn').Acorn} Acorn
* @typedef {import('micromark-util-events-to-acorn').AcornOptions} AcornOptions
*
* @typedef Options
* Configuration (optional).
* @property {Acorn | null | undefined} [acorn]
* Acorn parser to use (optional).
* @property {AcornOptions | null | undefined} [acornOptions]
* Options to pass to acorn (default: `{ecmaVersion: 2020, locations: true,
* sourceType: 'module'}`).
* All fields (except for `locations`) can be set.
* @property {boolean | null | undefined} [addResult=false]
* Whether to add an `estree` field to `mdxFlowExpression` and
* `mdxTextExpression` tokens with results from acorn.
* @property {boolean | null | undefined} [spread=false]
* Undocumented option to parse only a spread (used by
* `micromark-extension-mdx-jsx` to parse spread attributes).
* @property {boolean | null | undefined} [allowEmpty=true]
* Undocumented option to disallow empty attributes (used by
* `micromark-extension-mdx-jsx` to prohobit empty attribute values).
*/
/**
* @typedef Options
* @property {boolean} [addResult=false]
* @property {Acorn} [acorn]
* @property {AcornOptions} [acornOptions]
* @property {boolean} [spread=false]
* @property {boolean} [allowEmpty=true]
*/
import {factoryMdxExpression} from 'micromark-factory-mdx-expression'
import {factorySpace} from 'micromark-factory-space'
import {markdownLineEnding} from 'micromark-util-character'
/**
* @param {Options} options
* Add support for MDX expressions.
*
* Function called optionally with options to get a syntax extension for
* micromark.
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {Extension}
* Syntax extension for micromark (passed in `extensions`).
*/
export function mdxExpression(options = {}) {
const addResult = options.addResult
const acorn = options.acorn // Hidden: `micromark-extension-mdx-jsx` supports expressions in tags,
export function mdxExpression(options) {
const options_ = options || {}
const addResult = options_.addResult
const acorn = options_.acorn
// Hidden: `micromark-extension-mdx-jsx` supports expressions in tags,
// and one of them is only “spread” elements.

@@ -33,13 +52,9 @@ // It also has expressions that are not allowed to be empty (`<x y={}/>`).

// to test that behavior.
const spread = options.spread
let allowEmpty = options.allowEmpty
const spread = options_.spread
let allowEmpty = options_.allowEmpty
/** @type {AcornOptions} */
let acornOptions
if (allowEmpty === null || allowEmpty === undefined) {
allowEmpty = true
}
if (acorn) {

@@ -51,3 +66,2 @@ if (!acorn.parseExpressionAt) {

}
acornOptions = Object.assign(

@@ -58,8 +72,7 @@ {

},
options.acornOptions
options_.acornOptions
)
} else if (options.acornOptions || options.addResult) {
} else if (options_.acornOptions || options_.addResult) {
throw new Error('Expected an `acorn` instance passed in as `options.acorn`')
}
return {

@@ -78,9 +91,12 @@ flow: {

}
/** @type {Tokenizer} */
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeFlowExpression(effects, ok, nok) {
const self = this
return start
/** @type {State} */
function start(code) {

@@ -101,4 +117,4 @@ return factoryMdxExpression.call(

}
/** @type {State} */
function after(code) {

@@ -108,9 +124,12 @@ return code === null || markdownLineEnding(code) ? ok(code) : nok(code)

}
/** @type {Tokenizer} */
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeTextExpression(effects, ok) {
const self = this
return start
/** @type {State} */
function start(code) {

@@ -117,0 +136,0 @@ return factoryMdxExpression.call(

{
"name": "micromark-extension-mdx-expression",
"version": "1.0.3",
"version": "1.0.4",
"description": "micromark extension to support MDX or MDX JS expressions",

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

"scripts": {
"build": "rimraf \"*.d.ts\" \"{dev/,lib/}**/*.d.ts\" && tsc && micromark-build && type-coverage"
"build": "tsc --build --clean && tsc && type-coverage && micromark-build"
},

@@ -62,0 +62,0 @@ "xo": 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