///
import { PluginError } from '../errors/PluginError';
import type { ClosureTree } from "./ClosureTree";
import type { Environment } from "../Environment";
import type { Expression as ExpressionNode, SourceLocation, Statement as StatementNode } from 'estree';
import type { GoogTrans } from '../transformation/transform/GoogTrans';
export declare enum ModuleState {
UNLOAD = 0,
CACHE = 1,
LOAD = 2
}
export declare enum ModuleType {
/** A script file that contains goog.module. */
GOOG = 0,
/** ECMAScript module. */
ES = 1,
/** CommonJS module. */
COMMONJS = 2,
/** A script file that contains goog.provide. */
PROVIDE = 3,
/** A script file that does not contains goog.provide or goog.module. */
SCRIPT = 4
}
/** Represent a single JSDoc annotation, with an optional argument, e.g. @provideGoog, @type {string}. */
export interface ClosureCommentAnnotation {
name: string;
value?: string;
loc?: SourceLocation;
}
/** Used to store parsed goog.define parameters. */
export interface DefineParam {
/** The goog.define expression. */
expr: ExpressionNode;
/** The name parameter. */
name: string;
/** The stringfied defaultValue parameter. */
value: string;
/**
* Is the left part missing, to compat the google-closure-library@<=20190301.0.0,
* e.g. https://github.com/google/closure-library/blob/1488aa237/closure/goog/base.js#L213
*/
missingLeft?: boolean;
}
/** Dependency param that used to store parsed goog.addDependency parameters. */
export interface DependencyParam {
/** Source of the goog.addDependency statement. */
text: string;
/** The relative path from base.js to the js file. */
relPath: string;
/** An array of strings with the names of the objects this file provides. */
provides: string[];
/** An array of strings with the names of the objects this file requires. */
requires: string[];
/** Parameters indicate the Closure module type and language version. */
flags: {
module?: string;
lang?: string;
};
}
export declare function instanceOfDependencyParam(object: any): object is DependencyParam;
/** More information see {@link ClosureModule.getNamespaceType}. */
export interface NamespaceType {
/** Always "unknow" outside PROVIDE and legacy GOOG module. */
type: 'provide' | 'require' | 'implicit' | 'unknow';
/** Its owner namespace. */
owner?: string;
}
/** Closure module provide information. */
export interface ProvideInfo {
/** This provided namespace. */
fullname: string;
/** The provide expression, e.g. goog.module/provide/declareModuleId/declareNamespace. */
expr?: ExpressionNode;
/** The provide statement. */
statement?: StatementNode;
/** The implicit namespaces need construct, only defined in PROVIDE and legacy GOOG module. */
implicities?: string[];
/** Exported local variable, defaults to exports, only defined in base.js and GOOG module. */
id?: string;
/** Declaration of the exported local variable, only defined in GOOG module. */
declaration?: StatementNode;
}
/** Closure module require information. */
export interface RequireInfo {
/** This required namespace. */
fullname: string;
/** True if get from goog.require expression. */
confirmed: boolean;
/** Insert position for transformed import statement. */
position: number;
/** The goog.require expression, undefined if not confirmed. */
expr?: ExpressionNode;
/** The goog.require statement. */
statement?: StatementNode;
/** True if the goog.require expression result is used. */
used?: boolean;
}
export declare class ClosureModule {
tree: ClosureTree | undefined;
env: Environment;
request: string;
source?: string;
parser: any;
state: ModuleState;
/** True if this module is the base.js file. */
isbase: boolean;
/** True if this module is a dependencies file like the deps.js in Closure library. */
isdeps: boolean;
type: ModuleType;
/** True if goog.module.declareLegacyNamespace missing. */
legacy: true | StatementNode | undefined;
lang: string;
provides: Map;
requires: Map;
/** Record namespace usages in PROVIDE and legacy GOOG module. */
namespaceUsages: Map;
/** Cache of namespace types. */
namespaceTypes: Map;
/** Parsed goog.define parameters in this module. */
defineParams: Map;
/** Some GoogTrans ready to apply. */
trans: GoogTrans[];
/** Errors when parsing. */
errors: PluginError[];
/** Warnings when parsing. */
warnings: PluginError[];
/**
* @param options.request - An absolute file.
*/
constructor(options: {
request: string;
tree: ClosureTree;
env: Environment;
parser: any;
});
/**
* @param namespace - Full namespce, dot-separated sequence of a-z, A-Z, 0-9, _ and $.
* @throws {@link InvalidNamespaceError} Throw if invalid namespace grammar;
* @throws {@link NamespaceConflictError} Throw if namespace conflict with builtin object;
* @throws {@link NamespaceConflictError} Throw if namespace start with goog but not Closure library module;
* @throws {@link NamespaceDuplicateError} Throw if namespace duplicate;
*/
addProvide(namespace: string, info?: ProvideInfo): void;
/**
* @param namespace - Full namespce, dot-separated sequence of a-z, A-Z, 0-9, _ and $.
* @throws {@link NamespaceDuplicateError} Throw if namespace duplicate;
*/
addRequire(namespace: string, info?: RequireInfo): void;
/**
* Get the namespace type information.
* !!This method just work after all goog.require/provide/module/declareLegacyNamespace statements has parsed.
* If this module provide namespace "a", type of namespace "b" is "unknow" and its owner is undefined;
* If this module provide namespace "a.b", type of namespace "a.b.c" is "provide" and its owner is "a.b";
* If this module require namespace "a.b", type of namespace "a.b.c" is "require" and its owner is "a.b";
* If this module provide/require namespace "a.b", type of namespace "a.c" is "implicit" and its owner is "a";
* @param namespace - Full namespace, dot-separated sequence of a-z, A-Z, 0-9, _ and $.
*/
getNamespaceType(namespace: string): NamespaceType;
/** Load from request, goog.addDependency params or source. */
load(arg: string | Buffer | DependencyParam | null | undefined): void;
/** Parse and fill the implicit namespaces of all provide informations, its auto execute while parsing. */
parseImplicities(): void;
private _unload;
unload(): void;
}