Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

Commit 07b9df9

Browse files
committed
revert to cjs module re: syntax-tree/hastscript#16
see syntax-tree/unist#72
1 parent 7acd460 commit 07b9df9

File tree

5 files changed

+12
-16
lines changed

5 files changed

+12
-16
lines changed

index.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
"use strict";
2-
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.MultiError = void 0;
4-
const unist_util_visit_1 = require("unist-util-visit");
5-
class MultiError extends Error {
1+
import { visit } from "unist-util-visit";
2+
export class MultiError extends Error {
63
constructor(errors) {
74
super(`Multiple Errors Occured:`);
85
Object.defineProperty(this, "errors", {
@@ -15,7 +12,6 @@ class MultiError extends Error {
1512
this.errors = errors;
1613
}
1714
}
18-
exports.MultiError = MultiError;
1915
/**
2016
* Parses, stores, and optionally validates the contents of frontmatter blocks pasred by remark-frontmatter.
2117
*
@@ -39,11 +35,10 @@ const remarkMorematter = function (settings) {
3935
for (const key in handlers) {
4036
const { parser, validator, name = key } = handlers[key];
4137
const results = [];
42-
(0, unist_util_visit_1.visit)(tree, key, (node, index, parent) => {
38+
visit(tree, key, (node, index, parent) => {
4339
throwOnInvalidNodeType(node.type);
4440
//@ts-expect-error: We've already excluded invalid node types
4541
const value = parser(node.value);
46-
node.type;
4742
try {
4843
validator && validator(value);
4944
}
@@ -54,9 +49,10 @@ const remarkMorematter = function (settings) {
5449
}
5550
results.push(value);
5651
// Remove this node from the tree
57-
parent && index && parent.children.splice(index, 1);
52+
!!parent && !!index && parent.children.splice(index, 1);
5853
// Since we removed a node, continue visiting at the same index to avoid skipping nodes
59-
return index;
54+
if (index)
55+
return ++index;
6056
});
6157
file.data[name] = results;
6258
}
@@ -93,4 +89,4 @@ function throwOnInvalidNodeType(type) {
9389
throw new Error(`remark-morematter: handling ${type} node types is not supported`);
9490
}
9591
}
96-
exports.default = remarkMorematter;
92+
export default remarkMorematter;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "remark-morematter",
33
"version": "1.0.0",
4+
"type": "module",
45
"engines": {
56
"node": ">=14.16"
67
},

src/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ const remarkMorematter: Plugin<[Options|null], Root, Root> = function (
7272
throwOnInvalidNodeType(node.type);
7373
//@ts-expect-error: We've already excluded invalid node types
7474
const value = parser(node.value);
75-
node.type;
7675
try {
7776
validator && validator(value);
7877
} catch (error) {
@@ -82,9 +81,9 @@ const remarkMorematter: Plugin<[Options|null], Root, Root> = function (
8281
}
8382
results.push(value);
8483
// Remove this node from the tree
85-
parent && index && parent.children.splice(index, 1);
84+
!!parent && !!index && parent.children.splice(index, 1);
8685
// Since we removed a node, continue visiting at the same index to avoid skipping nodes
87-
return index;
86+
if (index) return ++index;
8887
});
8988
file.data[name] = results;
9089
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
2525

2626
/* Modules */
27-
"module": "node16", /* Specify what module code is generated. */
27+
"module": "ES2015", /* Specify what module code is generated. */
2828
// "rootDir": "./", /* Specify the root folder within your source files. */
2929
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
3030
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */

0 commit comments

Comments
 (0)