Skip to content

chore: more JSDoc imports #12588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/svelte/src/compiler/phases/1-parse/acorn.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/** @import { Comment, Program } from 'estree' */
/** @import { Node } from 'acorn' */
import * as acorn from 'acorn';
import { walk } from 'zimmerframe';
import { tsPlugin } from 'acorn-typescript';
Expand All @@ -23,7 +25,7 @@ export function parse(source, typescript) {
if (typescript) amend(source, ast);
add_comments(ast);

return /** @type {import('estree').Program} */ (ast);
return /** @type {Program} */ (ast);
}

/**
Expand Down Expand Up @@ -57,7 +59,7 @@ export function parse_expression_at(source, typescript, index) {
*/
function get_comment_handlers(source) {
/**
* @typedef {import('estree').Comment & {
* @typedef {Comment & {
* start: number;
* end: number;
* }} CommentWithLocation
Expand Down Expand Up @@ -149,7 +151,7 @@ function get_comment_handlers(source) {
/**
* Tidy up some stuff left behind by acorn-typescript
* @param {string} source
* @param {import('acorn').Node} node
* @param {Node} node
*/
function amend(source, node) {
return walk(node, null, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/** @import { Expression } from 'estree' */
/** @import { Parser } from '../index.js' */
import { parse_expression_at } from '../acorn.js';
import { regex_whitespace } from '../../patterns.js';
import * as e from '../../../errors.js';

/**
* @param {import('../index.js').Parser} parser
* @returns {import('estree').Expression}
* @param {Parser} parser
* @returns {Expression}
*/
export default function read_expression(parser) {
try {
Expand Down Expand Up @@ -35,7 +37,7 @@ export default function read_expression(parser) {

parser.index = index;

return /** @type {import('estree').Expression} */ (node);
return /** @type {Expression} */ (node);
} catch (err) {
parser.acorn_error(err);
}
Expand Down
5 changes: 3 additions & 2 deletions packages/svelte/src/compiler/phases/1-parse/state/element.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @import { Parser } from '../index.js' */
/** @import { Expression } from 'estree' */
/** @import * as Compiler from '#compiler' */
/** @import { Parser } from '../index.js' */
import { is_void } from '../../../../constants.js';
import read_expression from '../read/expression.js';
import { read_script } from '../read/script.js';
Expand Down Expand Up @@ -589,7 +590,7 @@ function read_attribute(parser) {

const first_value = value === true ? undefined : Array.isArray(value) ? value[0] : value;

/** @type {import('estree').Expression | null} */
/** @type {Expression | null} */
let expression = null;

if (first_value) {
Expand Down
49 changes: 26 additions & 23 deletions packages/svelte/src/compiler/phases/1-parse/state/tag.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/** @import { ArrowFunctionExpression, Expression, Identifier } from 'estree' */
/** @import { AwaitBlock, ConstTag, DebugTag, EachBlock, ExpressionTag, HtmlTag, IfBlock, KeyBlock, RenderTag, SnippetBlock } from '#compiler' */
/** @import { Parser } from '../index.js' */
import read_pattern from '../read/context.js';
import read_expression from '../read/expression.js';
import * as e from '../../../errors.js';
Expand All @@ -7,7 +10,7 @@ import { parse_expression_at } from '../acorn.js';

const regex_whitespace_with_closing_curly_brace = /^\s*}/;

/** @param {import('../index.js').Parser} parser */
/** @param {Parser} parser */
export default function tag(parser) {
const start = parser.index;
parser.index += 1;
Expand All @@ -29,7 +32,7 @@ export default function tag(parser) {
parser.allow_whitespace();
parser.eat('}', true);

/** @type {ReturnType<typeof parser.append<import('#compiler').ExpressionTag>>} */
/** @type {ReturnType<typeof parser.append<ExpressionTag>>} */
parser.append({
type: 'ExpressionTag',
start,
Expand All @@ -42,15 +45,15 @@ export default function tag(parser) {
});
}

/** @param {import('../index.js').Parser} parser */
/** @param {Parser} parser */
function open(parser) {
let start = parser.index - 2;
while (parser.template[start] !== '{') start -= 1;

if (parser.eat('if')) {
parser.require_whitespace();

/** @type {ReturnType<typeof parser.append<import('#compiler').IfBlock>>} */
/** @type {ReturnType<typeof parser.append<IfBlock>>} */
const block = parser.append({
type: 'IfBlock',
elseif: false,
Expand All @@ -76,7 +79,7 @@ function open(parser) {
const template = parser.template;
let end = parser.template.length;

/** @type {import('estree').Expression | undefined} */
/** @type {Expression | undefined} */
let expression;

// we have to do this loop because `{#each x as { y = z }}` fails to parse —
Expand Down Expand Up @@ -119,7 +122,7 @@ function open(parser) {
expression = walk(expression, null, {
// @ts-expect-error
TSAsExpression(node, context) {
if (node.end === /** @type {import('estree').Expression} */ (expression).end) {
if (node.end === /** @type {Expression} */ (expression).end) {
assertion = node;
end = node.expression.end;
return node.expression;
Expand Down Expand Up @@ -171,7 +174,7 @@ function open(parser) {

parser.eat('}', true);

/** @type {ReturnType<typeof parser.append<import('#compiler').EachBlock>>} */
/** @type {ReturnType<typeof parser.append<EachBlock>>} */
const block = parser.append({
type: 'EachBlock',
start,
Expand All @@ -195,7 +198,7 @@ function open(parser) {
const expression = read_expression(parser);
parser.allow_whitespace();

/** @type {ReturnType<typeof parser.append<import('#compiler').AwaitBlock>>} */
/** @type {ReturnType<typeof parser.append<AwaitBlock>>} */
const block = parser.append({
type: 'AwaitBlock',
start,
Expand Down Expand Up @@ -249,7 +252,7 @@ function open(parser) {

parser.eat('}', true);

/** @type {ReturnType<typeof parser.append<import('#compiler').KeyBlock>>} */
/** @type {ReturnType<typeof parser.append<KeyBlock>>} */
const block = parser.append({
type: 'KeyBlock',
start,
Expand Down Expand Up @@ -293,14 +296,14 @@ function open(parser) {
const prelude = parser.template.slice(0, params_start).replace(/\S/g, ' ');
const params = parser.template.slice(params_start, parser.index);

let function_expression = /** @type {import('estree').ArrowFunctionExpression} */ (
let function_expression = /** @type {ArrowFunctionExpression} */ (
parse_expression_at(prelude + `${params} => {}`, parser.ts, params_start)
);

parser.allow_whitespace();
parser.eat('}', true);

/** @type {ReturnType<typeof parser.append<import('#compiler').SnippetBlock>>} */
/** @type {ReturnType<typeof parser.append<SnippetBlock>>} */
const block = parser.append({
type: 'SnippetBlock',
start,
Expand All @@ -323,7 +326,7 @@ function open(parser) {
e.expected_block_type(parser.index);
}

/** @param {import('../index.js').Parser} parser */
/** @param {Parser} parser */
function next(parser) {
const start = parser.index - 1;

Expand Down Expand Up @@ -352,7 +355,7 @@ function next(parser) {
let elseif_start = start - 1;
while (parser.template[elseif_start] !== '{') elseif_start -= 1;

/** @type {ReturnType<typeof parser.append<import('#compiler').IfBlock>>} */
/** @type {ReturnType<typeof parser.append<IfBlock>>} */
const child = parser.append({
start: elseif_start,
end: -1,
Expand Down Expand Up @@ -434,7 +437,7 @@ function next(parser) {
e.block_invalid_continuation_placement(start);
}

/** @param {import('../index.js').Parser} parser */
/** @param {Parser} parser */
function close(parser) {
const start = parser.index - 1;

Expand All @@ -448,7 +451,7 @@ function close(parser) {
while (block.elseif) {
block.end = parser.index;
parser.stack.pop();
block = /** @type {import('#compiler').IfBlock} */ (parser.current());
block = /** @type {IfBlock} */ (parser.current());
}
block.end = parser.index;
parser.pop();
Expand Down Expand Up @@ -482,7 +485,7 @@ function close(parser) {
parser.pop();
}

/** @param {import('../index.js').Parser} parser */
/** @param {Parser} parser */
function special(parser) {
let start = parser.index;
while (parser.template[start] !== '{') start -= 1;
Expand All @@ -496,7 +499,7 @@ function special(parser) {
parser.allow_whitespace();
parser.eat('}', true);

/** @type {ReturnType<typeof parser.append<import('#compiler').HtmlTag>>} */
/** @type {ReturnType<typeof parser.append<HtmlTag>>} */
parser.append({
type: 'HtmlTag',
start,
Expand All @@ -508,7 +511,7 @@ function special(parser) {
}

if (parser.eat('debug')) {
/** @type {import('estree').Identifier[]} */
/** @type {Identifier[]} */
let identifiers;

// Implies {@debug} which indicates "debug all"
Expand All @@ -519,8 +522,8 @@ function special(parser) {

identifiers =
expression.type === 'SequenceExpression'
? /** @type {import('estree').Identifier[]} */ (expression.expressions)
: [/** @type {import('estree').Identifier} */ (expression)];
? /** @type {Identifier[]} */ (expression.expressions)
: [/** @type {Identifier} */ (expression)];

identifiers.forEach(
/** @param {any} node */ (node) => {
Expand All @@ -534,7 +537,7 @@ function special(parser) {
parser.eat('}', true);
}

/** @type {ReturnType<typeof parser.append<import('#compiler').DebugTag>>} */
/** @type {ReturnType<typeof parser.append<DebugTag>>} */
parser.append({
type: 'DebugTag',
start,
Expand Down Expand Up @@ -567,7 +570,7 @@ function special(parser) {

parser.eat('}', true);

/** @type {ReturnType<typeof parser.append<import('#compiler').ConstTag>>} */
/** @type {ReturnType<typeof parser.append<ConstTag>>} */
parser.append({
type: 'ConstTag',
start,
Expand Down Expand Up @@ -598,7 +601,7 @@ function special(parser) {
parser.allow_whitespace();
parser.eat('}', true);

/** @type {ReturnType<typeof parser.append<import('#compiler').RenderTag>>} */
/** @type {ReturnType<typeof parser.append<RenderTag>>} */
parser.append({
type: 'RenderTag',
start,
Expand Down
Loading
Loading