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

Commit

Permalink
revert to cjs module re: syntax-tree/hastscript#16
Browse files Browse the repository at this point in the history
  • Loading branch information
helmturner committed Jul 8, 2022
1 parent 7acd460 commit 07b9df9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 7 additions & 11 deletions index.js
@@ -1,8 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MultiError = void 0;
const unist_util_visit_1 = require("unist-util-visit");
class MultiError extends Error {
import { visit } from "unist-util-visit";
export class MultiError extends Error {
constructor(errors) {
super(`Multiple Errors Occured:`);
Object.defineProperty(this, "errors", {
Expand All @@ -15,7 +12,6 @@ class MultiError extends Error {
this.errors = errors;
}
}
exports.MultiError = MultiError;
/**
* Parses, stores, and optionally validates the contents of frontmatter blocks pasred by remark-frontmatter.
*
Expand All @@ -39,11 +35,10 @@ const remarkMorematter = function (settings) {
for (const key in handlers) {
const { parser, validator, name = key } = handlers[key];
const results = [];
(0, unist_util_visit_1.visit)(tree, key, (node, index, parent) => {
visit(tree, key, (node, index, parent) => {
throwOnInvalidNodeType(node.type);
//@ts-expect-error: We've already excluded invalid node types
const value = parser(node.value);
node.type;
try {
validator && validator(value);
}
Expand All @@ -54,9 +49,10 @@ const remarkMorematter = function (settings) {
}
results.push(value);
// Remove this node from the tree
parent && index && parent.children.splice(index, 1);
!!parent && !!index && parent.children.splice(index, 1);
// Since we removed a node, continue visiting at the same index to avoid skipping nodes
return index;
if (index)
return ++index;
});
file.data[name] = results;
}
Expand Down Expand Up @@ -93,4 +89,4 @@ function throwOnInvalidNodeType(type) {
throw new Error(`remark-morematter: handling ${type} node types is not supported`);
}
}
exports.default = remarkMorematter;
export default remarkMorematter;
1 change: 1 addition & 0 deletions package.json
@@ -1,6 +1,7 @@
{
"name": "remark-morematter",
"version": "1.0.0",
"type": "module",
"engines": {
"node": ">=14.16"
},
Expand Down
5 changes: 2 additions & 3 deletions src/index.ts
Expand Up @@ -72,7 +72,6 @@ const remarkMorematter: Plugin<[Options|null], Root, Root> = function (
throwOnInvalidNodeType(node.type);
//@ts-expect-error: We've already excluded invalid node types
const value = parser(node.value);
node.type;
try {
validator && validator(value);
} catch (error) {
Expand All @@ -82,9 +81,9 @@ const remarkMorematter: Plugin<[Options|null], Root, Root> = function (
}
results.push(value);
// Remove this node from the tree
parent && index && parent.children.splice(index, 1);
!!parent && !!index && parent.children.splice(index, 1);
// Since we removed a node, continue visiting at the same index to avoid skipping nodes
return index;
if (index) return ++index;
});
file.data[name] = results;
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Expand Up @@ -24,7 +24,7 @@
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */

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

0 comments on commit 07b9df9

Please sign in to comment.