cleanup script.js/context.js

pull/8569/head
Simon Holthausen 3 years ago
parent db8b24eff5
commit 1d2b073e9c

@ -12,7 +12,7 @@ import { regex_not_newline_characters } from '../../utils/patterns.js';
/** /**
* @param {import('../index.js').Parser} parser * @param {import('../index.js').Parser} parser
* @returns {Pattern & { start: number; end: number }} * @returns {import('estree').Pattern & { start: number; end: number }}
*/ */
export default function read_context(parser) { export default function read_context(parser) {
const start = parser.index; const start = parser.index;
@ -73,8 +73,9 @@ export default function read_context(parser) {
space_with_newline = space_with_newline =
space_with_newline.slice(0, first_space) + space_with_newline.slice(first_space + 1); space_with_newline.slice(0, first_space) + space_with_newline.slice(first_space + 1);
return (parse_expression_at(`${space_with_newline}(${pattern_string} = 1)`, start - 1) as any) return /** @type {any} */ (
.left; parse_expression_at(`${space_with_newline}(${pattern_string} = 1)`, start - 1)
).left;
} catch (error) { } catch (error) {
parser.acorn_error(error); parser.acorn_error(error);
} }

@ -1,11 +1,12 @@
import * as acorn from '../acorn'; import * as acorn from '../acorn.js';
import parser_errors from '../errors'; import parser_errors from '../errors.js';
import { regex_not_newline_characters } from '../../utils/patterns'; import { regex_not_newline_characters } from '../../utils/patterns.js';
const regex_closing_script_tag = /<\/script\s*>/; const regex_closing_script_tag = /<\/script\s*>/;
const regex_starts_with_closing_script_tag = /^<\/script\s*>/; const regex_starts_with_closing_script_tag = /^<\/script\s*>/;
/** /**
* @param {Parser} parser * @param {import('../index.js').Parser} parser
* @param {any[]} attributes * @param {any[]} attributes
* @param {number} start * @param {number} start
* @returns {string} * @returns {string}
@ -24,10 +25,10 @@ function get_context(parser, attributes, start) {
} }
/** /**
* @param {Parser} parser * @param {import('../index.js').Parser} parser
* @param {number} start * @param {number} start
* @param {Node[]} attributes * @param {import('estree').Node[]} attributes
* @returns {Script} * @returns {import('../../interfaces.js').Script}
*/ */
export default function read_script(parser, start, attributes) { export default function read_script(parser, start, attributes) {
const script_start = parser.index; const script_start = parser.index;
@ -40,7 +41,7 @@ export default function read_script(parser, start, attributes) {
parser.read(regex_starts_with_closing_script_tag); parser.read(regex_starts_with_closing_script_tag);
/** /**
* @type {Program} * @type {import('estree').Program}
*/ */
let ast; let ast;
try { try {
@ -49,7 +50,7 @@ export default function read_script(parser, start, attributes) {
parser.acorn_error(err); parser.acorn_error(err);
} }
// TODO is this necessary? // TODO is this necessary?
ast.start = script_start; /** @type {any} */ (ast).start = script_start;
return { return {
type: 'Script', type: 'Script',
start, start,

Loading…
Cancel
Save