Skip to content
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

fix: even more types #4373

Merged
merged 5 commits into from Feb 5, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions browser/resolveId.ts
@@ -1,5 +1,5 @@
import { CustomPluginOptions, Plugin, ResolvedId, ResolveIdResult } from '../src/rollup/types';
import { PluginDriver } from '../src/utils/PluginDriver';
import type { CustomPluginOptions, Plugin, ResolvedId, ResolveIdResult } from '../src/rollup/types';
import type { PluginDriver } from '../src/utils/PluginDriver';
import { resolveIdViaPlugins } from '../src/utils/resolveIdViaPlugins';
import { throwNoFileSystem } from './error';

Expand Down
2 changes: 1 addition & 1 deletion build-plugins/add-cli-entry.ts
@@ -1,5 +1,5 @@
import MagicString from 'magic-string';
import { Plugin } from 'rollup';
import type { Plugin } from 'rollup';

export default function addCliEntry(): Plugin {
return {
Expand Down
2 changes: 1 addition & 1 deletion build-plugins/emit-module-package-file.ts
@@ -1,4 +1,4 @@
import { Plugin } from 'rollup';
import type { Plugin } from 'rollup';

export default function emitModulePackageFile(): Plugin {
return {
Expand Down
2 changes: 1 addition & 1 deletion build-plugins/esm-dynamic-import.ts
@@ -1,4 +1,4 @@
import { Plugin } from 'rollup';
import type { Plugin } from 'rollup';

export default function addBinShebangAndEsmImport(): Plugin {
let importFound = false;
Expand Down
1 change: 1 addition & 0 deletions cli/cli.ts
@@ -1,3 +1,4 @@
import process from 'process';
import help from 'help.md';
import { version } from 'package.json';
import argParser from 'yargs-parser';
Expand Down
5 changes: 3 additions & 2 deletions cli/logging.ts
@@ -1,9 +1,10 @@
import { RollupError } from '../src/rollup/types';
import process from 'process';
import type { RollupError } from '../src/rollup/types';
import { bold, cyan, dim, red } from '../src/utils/colors';
import relativeId from '../src/utils/relativeId';

// log to stderr to keep `rollup main.js > bundle.js` from breaking
export const stderr = (...args: unknown[]) => process.stderr.write(`${args.join('')}\n`);
export const stderr = (...args: readonly unknown[]) => process.stderr.write(`${args.join('')}\n`);

export function handleError(err: RollupError, recover = false): void {
let description = err.message || err;
Expand Down
2 changes: 1 addition & 1 deletion cli/run/batchWarnings.ts
@@ -1,4 +1,4 @@
import { RollupWarning } from '../../src/rollup/types';
import type { RollupWarning } from '../../src/rollup/types';
import { bold, gray, yellow } from '../../src/utils/colors';
import { getOrCreate } from '../../src/utils/getOrCreate';
import { printQuotedStringList } from '../../src/utils/printStringList';
Expand Down
1 change: 1 addition & 0 deletions cli/run/build.ts
@@ -1,3 +1,4 @@
import process from 'process';
import ms from 'pretty-ms';
import { rollup } from '../../src/node-entry';
import type { MergedRollupOptions } from '../../src/rollup/types';
Expand Down
6 changes: 3 additions & 3 deletions cli/run/commandPlugins.ts
@@ -1,5 +1,5 @@
import * as path from 'path';
import { InputOptions } from '../../src/rollup/types';
import { resolve } from 'path';
import type { InputOptions } from '../../src/rollup/types';
import { stdinPlugin } from './stdin';
import { waitForInputPlugin } from './waitForInput';

Expand Down Expand Up @@ -71,7 +71,7 @@ async function loadAndRegisterPlugin(
}
if (!plugin) {
try {
if (pluginText[0] == '.') pluginText = path.resolve(pluginText);
if (pluginText[0] == '.') pluginText = resolve(pluginText);
plugin = await requireOrImport(pluginText);
} catch (err: any) {
throw new Error(`Cannot load plugin "${pluginText}": ${err.message}.`);
Expand Down
4 changes: 2 additions & 2 deletions cli/run/index.ts
@@ -1,9 +1,9 @@
import { MergedRollupOptions } from '../../src/rollup/types';
import type { MergedRollupOptions } from '../../src/rollup/types';
import { isWatchEnabled } from '../../src/utils/options/mergeOptions';
import { getAliasName } from '../../src/utils/relativeId';
import { loadFsEvents } from '../../src/watch/fsevents-importer';
import { handleError } from '../logging';
import { BatchWarnings } from './batchWarnings';
import type { BatchWarnings } from './batchWarnings';
import build from './build';
import { getConfigPath } from './getConfigPath';
import loadAndParseConfigFile from './loadConfigFile';
Expand Down
3 changes: 2 additions & 1 deletion cli/run/loadConfigFile.ts
@@ -1,5 +1,6 @@
import { promises as fs } from 'fs';
import { extname, isAbsolute } from 'path';
import { version } from 'process';
import { pathToFileURL } from 'url';
import * as rollup from '../../src/node-entry';
import type { MergedRollupOptions } from '../../src/rollup/types';
Expand All @@ -13,7 +14,7 @@ import batchWarnings, { type BatchWarnings } from './batchWarnings';
import { addCommandPluginsToInputOptions, addPluginsFromCommandOption } from './commandPlugins';

function supportsNativeESM(): boolean {
return Number(/^v(\d+)/.exec(process.version)![1]) >= 13;
return Number(/^v(\d+)/.exec(version)![1]) >= 13;
}

interface NodeModuleWithCompile extends NodeModule {
Expand Down
5 changes: 3 additions & 2 deletions cli/run/loadConfigFromCommand.ts
@@ -1,6 +1,7 @@
import { MergedRollupOptions } from '../../src/rollup/types';
import process from 'process';
import type { MergedRollupOptions } from '../../src/rollup/types';
import { mergeOptions } from '../../src/utils/options/mergeOptions';
import batchWarnings, { BatchWarnings } from './batchWarnings';
import batchWarnings, { type BatchWarnings } from './batchWarnings';
import { addCommandPluginsToInputOptions } from './commandPlugins';
import { stdinName } from './stdin';

Expand Down
1 change: 1 addition & 0 deletions cli/run/stdin.ts
@@ -1,3 +1,4 @@
import process from 'process';
import type { Plugin } from '../../src/rollup/types';

export const stdinName = '-';
Expand Down
2 changes: 1 addition & 1 deletion cli/run/timings.ts
@@ -1,5 +1,5 @@
import prettyBytes from 'pretty-bytes';
import { SerializedTimings } from '../../src/rollup/types';
import type { SerializedTimings } from '../../src/rollup/types';
import { bold, underline } from '../../src/utils/colors';

export function printTimings(timings: SerializedTimings): void {
Expand Down
2 changes: 1 addition & 1 deletion src/ModuleLoader.ts
Expand Up @@ -16,6 +16,7 @@ import type {
ResolveIdResult
} from './rollup/types';
import type { PluginDriver } from './utils/PluginDriver';
import Queue from './utils/Queue';
import { EMPTY_OBJECT } from './utils/blank';
import {
errBadLoader,
Expand All @@ -31,7 +32,6 @@ import {
} from './utils/error';
import { promises as fs } from './utils/fs';
import { isAbsolute, isRelative, resolve } from './utils/path';
import { Queue } from './utils/queue';
import relativeId from './utils/relativeId';
import { resolveId } from './utils/resolveId';
import { timeEnd, timeStart } from './utils/timers';
Expand Down
4 changes: 2 additions & 2 deletions src/ast/CallOptions.ts
@@ -1,5 +1,5 @@
import SpreadElement from './nodes/SpreadElement';
import { ExpressionEntity } from './nodes/shared/Expression';
import type SpreadElement from './nodes/SpreadElement';
import type { ExpressionEntity } from './nodes/shared/Expression';

export const NO_ARGS = [];

Expand Down
4 changes: 2 additions & 2 deletions src/ast/Entity.ts
@@ -1,5 +1,5 @@
import { HasEffectsContext } from './ExecutionContext';
import { ObjectPath } from './utils/PathTracker';
import type { HasEffectsContext } from './ExecutionContext';
import type { ObjectPath } from './utils/PathTracker';

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Entity {}
Expand Down
6 changes: 3 additions & 3 deletions src/ast/ExecutionContext.ts
@@ -1,7 +1,7 @@
import { Entity } from './Entity';
import { ExpressionEntity } from './nodes/shared/Expression';
import type { Entity } from './Entity';
import type { ExpressionEntity } from './nodes/shared/Expression';
import { DiscriminatedPathTracker, PathTracker } from './utils/PathTracker';
import ThisVariable from './variables/ThisVariable';
import type ThisVariable from './variables/ThisVariable';

interface ExecutionContextIgnore {
breaks: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/ast/NodeEvents.ts
@@ -1,4 +1,5 @@
export const EVENT_ACCESSED = 0;
export const EVENT_ASSIGNED = 1;
export const EVENT_CALLED = 2;

export type NodeEvent = typeof EVENT_ACCESSED | typeof EVENT_ASSIGNED | typeof EVENT_CALLED;
2 changes: 1 addition & 1 deletion src/ast/keys.ts
@@ -1,4 +1,4 @@
import { GenericEsTreeNode } from './nodes/shared/Node';
import type { GenericEsTreeNode } from './nodes/shared/Node';

export const keys: {
[name: string]: string[];
Expand Down
20 changes: 10 additions & 10 deletions src/ast/nodes/ArrayExpression.ts
@@ -1,18 +1,18 @@
import { CallOptions } from '../CallOptions';
import { DeoptimizableEntity } from '../DeoptimizableEntity';
import { HasEffectsContext } from '../ExecutionContext';
import { NodeEvent } from '../NodeEvents';
import { ObjectPath, PathTracker, UnknownInteger } from '../utils/PathTracker';
import type { CallOptions } from '../CallOptions';
import type { DeoptimizableEntity } from '../DeoptimizableEntity';
import type { HasEffectsContext } from '../ExecutionContext';
import type { NodeEvent } from '../NodeEvents';
import { type ObjectPath, type PathTracker, UnknownInteger } from '../utils/PathTracker';
import { UNDEFINED_EXPRESSION, UNKNOWN_LITERAL_NUMBER } from '../values';
import * as NodeType from './NodeType';
import type * as NodeType from './NodeType';
import SpreadElement from './SpreadElement';
import { ARRAY_PROTOTYPE } from './shared/ArrayPrototype';
import { ExpressionEntity, LiteralValueOrUnknown } from './shared/Expression';
import { ExpressionNode, NodeBase } from './shared/Node';
import { ObjectEntity, ObjectProperty } from './shared/ObjectEntity';
import type { ExpressionEntity, LiteralValueOrUnknown } from './shared/Expression';
import { type ExpressionNode, NodeBase } from './shared/Node';
import { ObjectEntity, type ObjectProperty } from './shared/ObjectEntity';

export default class ArrayExpression extends NodeBase {
declare elements: (ExpressionNode | SpreadElement | null)[];
declare elements: readonly (ExpressionNode | SpreadElement | null)[];
declare type: NodeType.tArrayExpression;
private objectEntity: ObjectEntity | null = null;

Expand Down
16 changes: 8 additions & 8 deletions src/ast/nodes/ArrayPattern.ts
@@ -1,19 +1,19 @@
import { HasEffectsContext } from '../ExecutionContext';
import { EMPTY_PATH, ObjectPath } from '../utils/PathTracker';
import LocalVariable from '../variables/LocalVariable';
import Variable from '../variables/Variable';
import * as NodeType from './NodeType';
import type { HasEffectsContext } from '../ExecutionContext';
import { EMPTY_PATH, type ObjectPath } from '../utils/PathTracker';
import type LocalVariable from '../variables/LocalVariable';
import type Variable from '../variables/Variable';
import type * as NodeType from './NodeType';
import { UNKNOWN_EXPRESSION } from './shared/Expression';
import { NodeBase } from './shared/Node';
import { PatternNode } from './shared/Pattern';
import type { PatternNode } from './shared/Pattern';

export default class ArrayPattern extends NodeBase implements PatternNode {
declare elements: (PatternNode | null)[];
declare type: NodeType.tArrayPattern;

addExportedVariables(
variables: Variable[],
exportNamesByVariable: Map<Variable, string[]>
variables: readonly Variable[],
exportNamesByVariable: ReadonlyMap<Variable, readonly string[]>
): void {
for (const element of this.elements) {
if (element !== null) {
Expand Down
34 changes: 23 additions & 11 deletions src/ast/nodes/ArrowFunctionExpression.ts
@@ -1,22 +1,31 @@
import { NormalizedTreeshakingOptions } from '../../rollup/types';
import { CallOptions, NO_ARGS } from '../CallOptions';
import { BROKEN_FLOW_NONE, HasEffectsContext, InclusionContext } from '../ExecutionContext';
import type { NormalizedTreeshakingOptions } from '../../rollup/types';
import { type CallOptions, NO_ARGS } from '../CallOptions';
import {
BROKEN_FLOW_NONE,
type HasEffectsContext,
type InclusionContext
} from '../ExecutionContext';
import ReturnValueScope from '../scopes/ReturnValueScope';
import Scope from '../scopes/Scope';
import { ObjectPath, UNKNOWN_PATH, UnknownKey } from '../utils/PathTracker';
import type Scope from '../scopes/Scope';
import { type ObjectPath, UNKNOWN_PATH, UnknownKey } from '../utils/PathTracker';
import BlockStatement from './BlockStatement';
import Identifier from './Identifier';
import * as NodeType from './NodeType';
import RestElement from './RestElement';
import SpreadElement from './SpreadElement';
import { ExpressionEntity, UNKNOWN_EXPRESSION } from './shared/Expression';
import { ExpressionNode, GenericEsTreeNode, IncludeChildren, NodeBase } from './shared/Node';
import { PatternNode } from './shared/Pattern';
import type SpreadElement from './SpreadElement';
import { type ExpressionEntity, UNKNOWN_EXPRESSION } from './shared/Expression';
import {
type ExpressionNode,
type GenericEsTreeNode,
type IncludeChildren,
NodeBase
} from './shared/Node';
import type { PatternNode } from './shared/Pattern';

export default class ArrowFunctionExpression extends NodeBase {
declare async: boolean;
declare body: BlockStatement | ExpressionNode;
declare params: PatternNode[];
declare params: readonly PatternNode[];
declare preventChildBlockScope: true;
declare scope: ReturnValueScope;
declare type: NodeType.tArrowFunctionExpression;
Expand Down Expand Up @@ -116,7 +125,10 @@ export default class ArrowFunctionExpression extends NodeBase {
context.brokenFlow = brokenFlow;
}

includeCallArguments(context: InclusionContext, args: (ExpressionNode | SpreadElement)[]): void {
includeCallArguments(
context: InclusionContext,
args: readonly (ExpressionNode | SpreadElement)[]
): void {
this.scope.includeCallArguments(context, args);
}

Expand Down
20 changes: 12 additions & 8 deletions src/ast/nodes/AssignmentExpression.ts
@@ -1,25 +1,29 @@
import MagicString from 'magic-string';
import type MagicString from 'magic-string';
import { BLANK } from '../../utils/blank';
import {
findFirstOccurrenceOutsideComment,
findNonWhiteSpace,
NodeRenderOptions,
type NodeRenderOptions,
removeLineBreaks,
RenderOptions
type RenderOptions
} from '../../utils/renderHelpers';
import {
renderSystemExportExpression,
renderSystemExportFunction,
renderSystemExportSequenceAfterExpression
} from '../../utils/systemJsRendering';
import { createHasEffectsContext, HasEffectsContext, InclusionContext } from '../ExecutionContext';
import { EMPTY_PATH, ObjectPath, UNKNOWN_PATH } from '../utils/PathTracker';
import Variable from '../variables/Variable';
import {
createHasEffectsContext,
type HasEffectsContext,
type InclusionContext
} from '../ExecutionContext';
import { EMPTY_PATH, type ObjectPath, UNKNOWN_PATH } from '../utils/PathTracker';
import type Variable from '../variables/Variable';
import Identifier from './Identifier';
import * as NodeType from './NodeType';
import ObjectPattern from './ObjectPattern';
import { ExpressionNode, IncludeChildren, NodeBase } from './shared/Node';
import { PatternNode } from './shared/Pattern';
import { type ExpressionNode, type IncludeChildren, NodeBase } from './shared/Node';
import type { PatternNode } from './shared/Pattern';

export default class AssignmentExpression extends NodeBase {
declare left: ExpressionNode | PatternNode;
Expand Down
24 changes: 12 additions & 12 deletions src/ast/nodes/AssignmentPattern.ts
@@ -1,14 +1,14 @@
import MagicString from 'magic-string';
import type MagicString from 'magic-string';
import { BLANK } from '../../utils/blank';
import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
import { HasEffectsContext } from '../ExecutionContext';
import { EMPTY_PATH, ObjectPath, UNKNOWN_PATH } from '../utils/PathTracker';
import LocalVariable from '../variables/LocalVariable';
import Variable from '../variables/Variable';
import * as NodeType from './NodeType';
import { ExpressionEntity } from './shared/Expression';
import { ExpressionNode, NodeBase } from './shared/Node';
import { PatternNode } from './shared/Pattern';
import type { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
import type { HasEffectsContext } from '../ExecutionContext';
import { EMPTY_PATH, type ObjectPath, UNKNOWN_PATH } from '../utils/PathTracker';
import type LocalVariable from '../variables/LocalVariable';
import type Variable from '../variables/Variable';
import type * as NodeType from './NodeType';
import type { ExpressionEntity } from './shared/Expression';
import { type ExpressionNode, NodeBase } from './shared/Node';
import type { PatternNode } from './shared/Pattern';

export default class AssignmentPattern extends NodeBase implements PatternNode {
declare left: PatternNode;
Expand All @@ -17,8 +17,8 @@ export default class AssignmentPattern extends NodeBase implements PatternNode {
protected deoptimized = false;

addExportedVariables(
variables: Variable[],
exportNamesByVariable: Map<Variable, string[]>
variables: readonly Variable[],
exportNamesByVariable: ReadonlyMap<Variable, readonly string[]>
): void {
this.left.addExportedVariables(variables, exportNamesByVariable);
}
Expand Down
6 changes: 3 additions & 3 deletions src/ast/nodes/AwaitExpression.ts
@@ -1,9 +1,9 @@
import { InclusionContext } from '../ExecutionContext';
import type { InclusionContext } from '../ExecutionContext';
import { UNKNOWN_PATH } from '../utils/PathTracker';
import ArrowFunctionExpression from './ArrowFunctionExpression';
import * as NodeType from './NodeType';
import type * as NodeType from './NodeType';
import FunctionNode from './shared/FunctionNode';
import { ExpressionNode, IncludeChildren, Node, NodeBase } from './shared/Node';
import { type ExpressionNode, type IncludeChildren, type Node, NodeBase } from './shared/Node';

export default class AwaitExpression extends NodeBase {
declare argument: ExpressionNode;
Expand Down