eslint-mdx
Advanced tools
Comparing version 0.9.5 to 0.9.6-beta.8
@@ -30,5 +30,5 @@ /// <reference path="../typings.d.ts" /> | ||
export declare function restoreNodeLocation<T extends BaseNode>(node: T, startLine: number, offset?: number): T; | ||
export declare const first: <T>(items: readonly T[] | T[]) => T; | ||
export declare const last: <T>(items: readonly T[] | T[]) => T; | ||
export declare const first: <T>(items: T[] | readonly T[]) => T; | ||
export declare const last: <T>(items: T[] | readonly T[]) => T; | ||
export declare const hasProperties: <T, P extends keyof T = keyof T>(obj: {}, properties: Arrayable<P>) => obj is T; | ||
//# sourceMappingURL=helper.d.ts.map |
"use strict"; | ||
// eslint-disable-next-line @typescript-eslint/no-triple-slash-reference | ||
// eslint-disable-next-line @typescript-eslint/triple-slash-reference | ||
/// <reference path="../typings.d.ts" /> | ||
@@ -28,2 +28,3 @@ var __assign = (this && this.__assign) || function () { | ||
if (typeof parser === 'string') { | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
parser = require(parser); | ||
@@ -43,3 +44,3 @@ } | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires | ||
var fallbackParser = require(fallback); | ||
@@ -54,4 +55,4 @@ parser = fallbackParser.parseForESLint || fallbackParser.parse; | ||
} | ||
return parser; | ||
} | ||
return parser; | ||
}; | ||
@@ -79,5 +80,3 @@ exports.normalizePosition = function (position) { | ||
if (Array.isArray(value)) { | ||
node[key] = value.map(function (child) { | ||
return restoreNodeLocation(child, startLine, offset); | ||
}); | ||
node[key] = value.map(function (child) { return restoreNodeLocation(child, startLine, offset); }); | ||
} | ||
@@ -84,0 +83,0 @@ else { |
@@ -10,4 +10,5 @@ import unified from 'unified'; | ||
export declare const DEFAULT_EXTENSIONS: readonly string[]; | ||
export declare const DEFAULT_PARSER_OPTIONS: ParserOptions; | ||
export declare class Parser { | ||
constructor(options?: ParserOptions); | ||
constructor(); | ||
normalizeJsxNode(node: Node, parent?: Parent): Node | Node[]; | ||
@@ -14,0 +15,0 @@ parse(code: string, options: ParserOptions): AST.Program; |
@@ -32,10 +32,15 @@ "use strict"; | ||
exports.DEFAULT_EXTENSIONS = ['.mdx']; | ||
exports.DEFAULT_PARSER_OPTIONS = { | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
ecmaVersion: new Date().getUTCFullYear(), | ||
sourceType: 'module', | ||
}; | ||
var Parser = /** @class */ (function () { | ||
function Parser( | ||
// @internal | ||
options) { | ||
this.options = options; | ||
function Parser() { | ||
// @internal | ||
this._options = exports.DEFAULT_PARSER_OPTIONS; | ||
this.parse = this.parse.bind(this); | ||
this.parseForESLint = this.parseForESLint.bind(this); | ||
this.nodeToAst = this.nodeToAst.bind(this); | ||
} | ||
@@ -47,3 +52,3 @@ Parser.prototype.normalizeJsxNode = function (node, parent) { | ||
} | ||
var matched = value.match(regexp_1.COMMENT_CONTENT_REGEX); | ||
var matched = regexp_1.COMMENT_CONTENT_REGEX.exec(value); | ||
if (matched) { | ||
@@ -85,3 +90,3 @@ var comments_1 = []; | ||
} | ||
return this.normalizeJsxNodes(node); | ||
return this._normalizeJsxNodes(node); | ||
}; | ||
@@ -93,9 +98,8 @@ Parser.prototype.parse = function (code, options) { | ||
var _this = this; | ||
this.options = options; | ||
if (!exports.DEFAULT_EXTENSIONS.concat(options.extensions || []).includes(path_1.default.extname(options.filePath))) { | ||
return this.eslintParse(code, options); | ||
return this._eslintParse(code, options); | ||
} | ||
var root = exports.mdxProcessor.parse(code); | ||
this.ast = __assign({}, helper_1.normalizePosition(root.position), { type: 'Program', sourceType: options.sourceType || 'module', body: [], comments: [], tokens: [] }); | ||
this.services = { | ||
this._ast = __assign({}, helper_1.normalizePosition(root.position), { type: 'Program', sourceType: options.sourceType || 'module', body: [], comments: [], tokens: [] }); | ||
this._services = { | ||
JSXElementsWithHTMLComments: [], | ||
@@ -110,18 +114,20 @@ }; | ||
normalized = Array.isArray(normalized) ? normalized : [normalized]; | ||
normalized.forEach(_this.nodeToAst); | ||
normalized.forEach(function (node) { return _this._nodeToAst(node, options); }); | ||
}, | ||
}); | ||
return { | ||
ast: this.ast, | ||
services: this.services, | ||
ast: this._ast, | ||
services: this._services, | ||
}; | ||
}; | ||
// @internal | ||
Parser.prototype.eslintParse = function (code, options) { | ||
if (options === void 0) { options = this.options; } | ||
if (!this.parser || options !== this.options) { | ||
this.options = options; | ||
this.parser = helper_1.normalizeParser(options.parser); | ||
Parser.prototype._eslintParse = function (code, options) { | ||
if (options === void 0) { options = this._options; } | ||
if (!this._parser || options.parser !== this._options.parser) { | ||
this._parser = helper_1.normalizeParser(options.parser); | ||
} | ||
var program = this.parser(code, options); | ||
if (options.filePath) { | ||
this._options = options; | ||
} | ||
var program = this._parser(code, options); | ||
return ('ast' in program && program.ast | ||
@@ -133,6 +139,6 @@ ? program | ||
// @internal | ||
Parser.prototype.normalizeJsxNodes = function (node) { | ||
Parser.prototype._normalizeJsxNodes = function (node) { | ||
var value = node.value; | ||
// wrap into single Fragment, so that it won't break on adjacent JSX nodes | ||
var program = this.eslintParse("<>" + value + "</>").ast; | ||
var program = this._eslintParse("<>" + value + "</>").ast; | ||
var expression = program.body[0].expression; | ||
@@ -173,6 +179,6 @@ if (!helper_1.isJsxNode(expression) || expression.children.length <= 1) { | ||
// @internal | ||
Parser.prototype.nodeToAst = function (node) { | ||
Parser.prototype._nodeToAst = function (node, options) { | ||
var _this = this; | ||
if (node.data && node.data.jsxType === 'JSXElementWithHTMLComments') { | ||
this.services.JSXElementsWithHTMLComments.push(node); | ||
this._services.JSXElementsWithHTMLComments.push(node); | ||
} | ||
@@ -188,3 +194,3 @@ var value = node.value; | ||
try { | ||
program = this.eslintParse(value).ast; | ||
program = this._eslintParse(value, options).ast; | ||
} | ||
@@ -202,3 +208,3 @@ catch (e) { | ||
var _a; | ||
return (_a = _this.ast[prop]).push.apply(_a, program[prop].map(function (item) { | ||
return (_a = _this._ast[prop]).push.apply(_a, program[prop].map(function (item) { | ||
return helper_1.restoreNodeLocation(item, startLine, offset); | ||
@@ -205,0 +211,0 @@ })); |
@@ -5,3 +5,3 @@ import { TraverseOptions } from './types'; | ||
export declare class Traverse { | ||
private _enter; | ||
private readonly _enter; | ||
constructor({ enter }: TraverseOptions); | ||
@@ -8,0 +8,0 @@ combineJsxNodes(nodes: Node[]): Node[]; |
@@ -7,3 +7,3 @@ import { JSXElement, JSXFragment } from '@babel/types'; | ||
}; | ||
export declare type JsxTypes = readonly [JSXElement['type'], JSXFragment['type']]; | ||
export declare type JsxTypes = Readonly<[JSXElement['type'], JSXFragment['type']]>; | ||
export declare type JsxType = JsxTypes[number]; | ||
@@ -10,0 +10,0 @@ export declare type Arrayable<T> = T[] | readonly T[]; |
{ | ||
"name": "eslint-mdx", | ||
"version": "0.9.5", | ||
"version": "0.9.6-beta.8+207f96a", | ||
"description": "ESLint Parser for MDX", | ||
"repository": "git@github.com:rx-ts/eslint-plugin-mdx.git", | ||
"repository": "git@github.com:rx-ts/eslint-mdx.git", | ||
"author": "JounQin <admin@1stg.me>", | ||
@@ -23,3 +23,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "a2094f7c5603eb2a52d7b3537afe4b09702218b5" | ||
"gitHead": "207f96a80bf883d1e37f7158c17cc8d07562f285" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
51063
28
618
1