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

micromark-factory-mdx-expression

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-factory-mdx-expression - npm Package Compare versions

Comparing version 1.0.9 to 2.0.0

10

dev/index.d.ts

@@ -19,9 +19,9 @@ /**

* @param {boolean | null | undefined} [addResult=false]
* Add `estree` to token.
* Add `estree` to token (default: `false`).
* @param {boolean | null | undefined} [spread=false]
* Support a spread (`{...a}`) only.
* Support a spread (`{...a}`) only (default: `false`).
* @param {boolean | null | undefined} [allowEmpty=false]
* Support an empty expression.
* Support an empty expression (default: `false`).
* @param {boolean | null | undefined} [allowLazy=false]
* Support lazy continuation of an expression.
* Support lazy continuation of an expression (default: `false`).
* @returns {State}

@@ -77,3 +77,3 @@ */

}
export type MdxSignal = MdxSignalOk | MdxSignalNok
export type MdxSignal = MdxSignalNok | MdxSignalOk
import {VFileMessage} from 'vfile-message'

@@ -27,13 +27,25 @@ /**

*
* @typedef {MdxSignalOk | MdxSignalNok} MdxSignal
* @typedef {MdxSignalNok | MdxSignalOk} MdxSignal
*/
import {ok as assert} from 'devlop'
import {markdownLineEnding} from 'micromark-util-character'
import {eventsToAcorn} from 'micromark-util-events-to-acorn'
import {codes} from 'micromark-util-symbol/codes.js'
import {types} from 'micromark-util-symbol/types.js'
import {codes, types} from 'micromark-util-symbol'
import {positionFromEstree} from 'unist-util-position-from-estree'
import {ok as assert} from 'uvu/assert'
import {VFileMessage} from 'vfile-message'
const trouble =
'https://github.com/micromark/micromark-extension-mdx-expression/tree/main/packages/micromark-extension-mdx-expression'
const unexpectedEofHash =
'#unexpected-end-of-file-in-expression-expected-a-corresponding-closing-brace-for-'
const unexpectedLazyHash =
'#unexpected-lazy-line-in-expression-in-container-expected-line-to-be-prefixed'
const nonSpreadHash =
'#unexpected-type-in-code-expected-an-object-spread-spread'
const spreadExtraHash =
'#unexpected-extra-content-in-spread-only-a-single-spread-is-supported'
const acornHash = '#could-not-parse-expression-with-acorn'
/**

@@ -57,9 +69,9 @@ * @this {TokenizeContext}

* @param {boolean | null | undefined} [addResult=false]
* Add `estree` to token.
* Add `estree` to token (default: `false`).
* @param {boolean | null | undefined} [spread=false]
* Support a spread (`{...a}`) only.
* Support a spread (`{...a}`) only (default: `false`).
* @param {boolean | null | undefined} [allowEmpty=false]
* Support an empty expression.
* Support an empty expression (default: `false`).
* @param {boolean | null | undefined} [allowLazy=false]
* Support lazy continuation of an expression.
* Support lazy continuation of an expression (default: `false`).
* @returns {State}

@@ -123,10 +135,14 @@ */

if (code === codes.eof) {
throw (
lastCrash ||
new VFileMessage(
'Unexpected end of file in expression, expected a corresponding closing brace for `{`',
self.now(),
'micromark-extension-mdx-expression:unexpected-eof'
)
if (lastCrash) throw lastCrash
const error = new VFileMessage(
'Unexpected end of file in expression, expected a corresponding closing brace for `{`',
{
place: self.now(),
ruleId: 'unexpected-eof',
source: 'micromark-extension-mdx-expression'
}
)
error.url = trouble + unexpectedEofHash
throw error
}

@@ -148,2 +164,3 @@

acornOptions,
chunkType,
eventStart,

@@ -230,9 +247,12 @@ pointStart,

) {
// `markdown-rs` uses:
// ``Unexpected lazy line in expression in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc``.
throw new VFileMessage(
'Unexpected end of file in expression, expected a corresponding closing brace for `{`',
self.now(),
'micromark-extension-mdx-expression:unexpected-eof'
const error = new VFileMessage(
'Unexpected lazy line in expression in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc',
{
place: self.now(),
ruleId: 'unexpected-lazy',
source: 'micromark-extension-mdx-expression'
}
)
error.url = trouble + unexpectedLazyHash
throw error
}

@@ -269,2 +289,3 @@

* @param {AcornOptions | null | undefined} acornOptions
* @param {TokenType} chunkType
* @param {number} eventStart

@@ -280,2 +301,3 @@ * @param {Point} pointStart

acornOptions,
chunkType,
eventStart,

@@ -289,2 +311,3 @@ pointStart,

acorn,
tokenTypes: [chunkType],
acornOptions,

@@ -306,4 +329,2 @@ start: pointStart,

// Can occur in some complex attributes.
/* c8 ignore next 11 */
if (

@@ -313,26 +334,45 @@ head.type !== 'ExpressionStatement' ||

) {
throw new VFileMessage(
const error = new VFileMessage(
'Unexpected `' +
head.type +
'` in code: expected an object spread (`{...spread}`)',
positionFromEstree(head).start,
'micromark-extension-mdx-expression:non-spread'
{
place: positionFromEstree(head).start,
ruleId: 'non-spread',
source: 'micromark-extension-mdx-expression'
}
)
} else if (head.expression.properties[1]) {
throw new VFileMessage(
error.url = trouble + nonSpreadHash
throw error
}
if (head.expression.properties[1]) {
const error = new VFileMessage(
'Unexpected extra content in spread: only a single spread is supported',
positionFromEstree(head.expression.properties[1]).start,
'micromark-extension-mdx-expression:spread-extra'
{
place: positionFromEstree(head.expression.properties[1]).start,
ruleId: 'spread-extra',
source: 'micromark-extension-mdx-expression'
}
)
} else if (
error.url = trouble + spreadExtraHash
throw error
}
if (
head.expression.properties[0] &&
head.expression.properties[0].type !== 'SpreadElement'
) {
throw new VFileMessage(
const error = new VFileMessage(
'Unexpected `' +
head.expression.properties[0].type +
'` in code: only spread elements are supported',
positionFromEstree(head.expression.properties[0]).start,
'micromark-extension-mdx-expression:non-spread'
{
place: positionFromEstree(head.expression.properties[0]).start,
ruleId: 'non-spread',
source: 'micromark-extension-mdx-expression'
}
)
error.url = trouble + nonSpreadHash
throw error
}

@@ -342,14 +382,15 @@ }

if (result.error) {
return {
type: 'nok',
message: new VFileMessage(
'Could not parse expression with acorn: ' + result.error.message,
{
line: result.error.loc.line,
column: result.error.loc.column + 1,
offset: result.error.pos
},
'micromark-extension-mdx-expression:acorn'
)
}
const error = new VFileMessage('Could not parse expression 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-mdx-expression'
})
error.url = trouble + acornHash
return {type: 'nok', message: error}
}

@@ -356,0 +397,0 @@

@@ -19,9 +19,9 @@ /**

* @param {boolean | null | undefined} [addResult=false]
* Add `estree` to token.
* Add `estree` to token (default: `false`).
* @param {boolean | null | undefined} [spread=false]
* Support a spread (`{...a}`) only.
* Support a spread (`{...a}`) only (default: `false`).
* @param {boolean | null | undefined} [allowEmpty=false]
* Support an empty expression.
* Support an empty expression (default: `false`).
* @param {boolean | null | undefined} [allowLazy=false]
* Support lazy continuation of an expression.
* Support lazy continuation of an expression (default: `false`).
* @returns {State}

@@ -77,3 +77,3 @@ */

}
export type MdxSignal = MdxSignalOk | MdxSignalNok
export type MdxSignal = MdxSignalNok | MdxSignalOk
import {VFileMessage} from 'vfile-message'

@@ -27,3 +27,3 @@ /**

*
* @typedef {MdxSignalOk | MdxSignalNok} MdxSignal
* @typedef {MdxSignalNok | MdxSignalOk} MdxSignal
*/

@@ -35,2 +35,13 @@

import {VFileMessage} from 'vfile-message'
const trouble =
'https://github.com/micromark/micromark-extension-mdx-expression/tree/main/packages/micromark-extension-mdx-expression'
const unexpectedEofHash =
'#unexpected-end-of-file-in-expression-expected-a-corresponding-closing-brace-for-'
const unexpectedLazyHash =
'#unexpected-lazy-line-in-expression-in-container-expected-line-to-be-prefixed'
const nonSpreadHash =
'#unexpected-type-in-code-expected-an-object-spread-spread'
const spreadExtraHash =
'#unexpected-extra-content-in-spread-only-a-single-spread-is-supported'
const acornHash = '#could-not-parse-expression-with-acorn'

@@ -55,9 +66,9 @@ /**

* @param {boolean | null | undefined} [addResult=false]
* Add `estree` to token.
* Add `estree` to token (default: `false`).
* @param {boolean | null | undefined} [spread=false]
* Support a spread (`{...a}`) only.
* Support a spread (`{...a}`) only (default: `false`).
* @param {boolean | null | undefined} [allowEmpty=false]
* Support an empty expression.
* Support an empty expression (default: `false`).
* @param {boolean | null | undefined} [allowLazy=false]
* Support lazy continuation of an expression.
* Support lazy continuation of an expression (default: `false`).
* @returns {State}

@@ -119,10 +130,13 @@ */

if (code === null) {
throw (
lastCrash ||
new VFileMessage(
'Unexpected end of file in expression, expected a corresponding closing brace for `{`',
self.now(),
'micromark-extension-mdx-expression:unexpected-eof'
)
if (lastCrash) throw lastCrash
const error = new VFileMessage(
'Unexpected end of file in expression, expected a corresponding closing brace for `{`',
{
place: self.now(),
ruleId: 'unexpected-eof',
source: 'micromark-extension-mdx-expression'
}
)
error.url = trouble + unexpectedEofHash
throw error
}

@@ -142,2 +156,3 @@ if (markdownLineEnding(code)) {

acornOptions,
chunkType,
eventStart,

@@ -223,9 +238,12 @@ pointStart,

) {
// `markdown-rs` uses:
// ``Unexpected lazy line in expression in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc``.
throw new VFileMessage(
'Unexpected end of file in expression, expected a corresponding closing brace for `{`',
self.now(),
'micromark-extension-mdx-expression:unexpected-eof'
const error = new VFileMessage(
'Unexpected lazy line in expression in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc',
{
place: self.now(),
ruleId: 'unexpected-lazy',
source: 'micromark-extension-mdx-expression'
}
)
error.url = trouble + unexpectedLazyHash
throw error
}

@@ -262,2 +280,3 @@

* @param {AcornOptions | null | undefined} acornOptions
* @param {TokenType} chunkType
* @param {number} eventStart

@@ -273,2 +292,3 @@ * @param {Point} pointStart

acornOptions,
chunkType,
eventStart,

@@ -282,2 +302,3 @@ pointStart,

acorn,
tokenTypes: [chunkType],
acornOptions,

@@ -297,4 +318,2 @@ start: pointStart,

const head = estree.body[0]
// Can occur in some complex attributes.
/* c8 ignore next 11 */
if (

@@ -304,40 +323,60 @@ head.type !== 'ExpressionStatement' ||

) {
throw new VFileMessage(
const error = new VFileMessage(
'Unexpected `' +
head.type +
'` in code: expected an object spread (`{...spread}`)',
positionFromEstree(head).start,
'micromark-extension-mdx-expression:non-spread'
{
place: positionFromEstree(head).start,
ruleId: 'non-spread',
source: 'micromark-extension-mdx-expression'
}
)
} else if (head.expression.properties[1]) {
throw new VFileMessage(
error.url = trouble + nonSpreadHash
throw error
}
if (head.expression.properties[1]) {
const error = new VFileMessage(
'Unexpected extra content in spread: only a single spread is supported',
positionFromEstree(head.expression.properties[1]).start,
'micromark-extension-mdx-expression:spread-extra'
{
place: positionFromEstree(head.expression.properties[1]).start,
ruleId: 'spread-extra',
source: 'micromark-extension-mdx-expression'
}
)
} else if (
error.url = trouble + spreadExtraHash
throw error
}
if (
head.expression.properties[0] &&
head.expression.properties[0].type !== 'SpreadElement'
) {
throw new VFileMessage(
const error = new VFileMessage(
'Unexpected `' +
head.expression.properties[0].type +
'` in code: only spread elements are supported',
positionFromEstree(head.expression.properties[0]).start,
'micromark-extension-mdx-expression:non-spread'
{
place: positionFromEstree(head.expression.properties[0]).start,
ruleId: 'non-spread',
source: 'micromark-extension-mdx-expression'
}
)
error.url = trouble + nonSpreadHash
throw error
}
}
if (result.error) {
const error = new VFileMessage('Could not parse expression 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-mdx-expression'
})
error.url = trouble + acornHash
return {
type: 'nok',
message: new VFileMessage(
'Could not parse expression with acorn: ' + result.error.message,
{
line: result.error.loc.line,
column: result.error.loc.column + 1,
offset: result.error.pos
},
'micromark-extension-mdx-expression:acorn'
)
message: error
}

@@ -344,0 +383,0 @@ }

{
"name": "micromark-factory-mdx-expression",
"version": "1.0.9",
"version": "2.0.0",
"description": "micromark factory to parse MDX expressions (found in JSX attributes, flow, text)",

@@ -30,4 +30,6 @@ "license": "MIT",

"type": "module",
"main": "index.js",
"types": "dev/index.d.ts",
"exports": {
"development": "./dev/index.js",
"default": "./index.js"
},
"files": [

@@ -38,15 +40,11 @@ "dev/",

],
"exports": {
"development": "./dev/index.js",
"default": "./index.js"
},
"dependencies": {
"@types/estree": "^1.0.0",
"micromark-util-character": "^1.0.0",
"micromark-util-events-to-acorn": "^1.0.0",
"micromark-util-symbol": "^1.0.0",
"micromark-util-types": "^1.0.0",
"devlop": "^1.0.0",
"micromark-util-character": "^2.0.0",
"micromark-util-events-to-acorn": "^2.0.0",
"micromark-util-symbol": "^2.0.0",
"micromark-util-types": "^2.0.0",
"unist-util-position-from-estree": "^1.0.0",
"uvu": "^0.5.0",
"vfile-message": "^3.0.0"
"vfile-message": "^4.0.0"
},

@@ -56,9 +54,9 @@ "scripts": {

},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
"ignoreCatch": true,
"strict": true
},
"xo": false
}

@@ -6,3 +6,3 @@ # micromark-factory-mdx-expression

[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][opencollective]

@@ -39,3 +39,3 @@ [![Backers][backers-badge]][opencollective]

```js
import {factoryMdxExpression} from 'https://esm.sh/micromark-factory-mdx-expression@1'
import {factoryMdxExpression} from 'https://esm.sh/micromark-factory-mdx-expression@2'
```

@@ -47,3 +47,3 @@

<script type="module">
import {factoryMdxExpression} from 'https://esm.sh/micromark-factory-mdx-expression@1?bundle'
import {factoryMdxExpression} from 'https://esm.sh/micromark-factory-mdx-expression@2?bundle'
</script>

@@ -55,5 +55,5 @@ ```

```js
import {ok as assert} from 'uvu/assert'
import {ok as assert} from 'devlop'
import {factoryMdxExpression} from 'micromark-factory-mdx-expression'
import {codes} from 'micromark-util-symbol/codes'
import {codes} from 'micromark-util-symbol'

@@ -138,9 +138,12 @@ // A micromark tokenizer that uses the factory:

Projects maintained by the unified collective are compatible with all maintained
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
As of now, that is Node.js 16+.
Our projects sometimes work with older versions, but this is not guaranteed.
These extensions work with `micromark` version 3+.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`micromark-factory-mdx-expression@^2`, compatible with Node.js 16.
This package works with `micromark` version `3` and later.
## Security

@@ -178,5 +181,5 @@

[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-factory-mdx-expression.svg
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-factory-mdx-expression
[bundle-size]: https://bundlephobia.com/result?p=micromark-factory-mdx-expression
[size]: https://bundlejs.com/?q=micromark-factory-mdx-expression

@@ -183,0 +186,0 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

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