add some missing types for validation

This commit is contained in:
Tobias Koppers 2018-05-11 14:13:06 +02:00
parent ab284977c3
commit 162ed5f382
3 changed files with 21 additions and 8 deletions

15
declarations.d.ts vendored
View File

@ -110,7 +110,7 @@ declare module "@webassemblyjs/ast" {
Start?: (p: NodePath<Start>) => void;
Global?: (p: NodePath<Global>) => void;
}
);
): void;
export class NodePath<T> {
node: T;
}
@ -121,14 +121,15 @@ declare module "@webassemblyjs/ast" {
export class Start extends Node {
index: Identifier;
}
export class ModuleImportDescription {
type: string;
valtype?: string;
id?: Identifier;
signature?: Signature;
}
export class ModuleImport extends Node {
module: string;
descr: {
type: string;
valtype?: string;
id?: Identifier;
signature?: Signature;
};
descr: ModuleImportDescription;
name: string;
}
export class ModuleExport extends Node {

View File

@ -262,6 +262,10 @@ class Module extends DependenciesBlock {
}
}
/**
* @param {string=} exportName the name of the export
* @returns {boolean|string} false if the export isn't used, true if no exportName is provided and the module is used, or the name to access it if the export is used
*/
isUsed(exportName) {
if (!exportName) return this.used !== false;
if (this.used === null || this.usedExports === null) return exportName;

View File

@ -8,12 +8,20 @@ const DependencyReference = require("./DependencyReference");
const ModuleDependency = require("./ModuleDependency");
const UnsupportedWebAssemblyFeatureError = require("../wasm/UnsupportedWebAssemblyFeatureError");
/** @typedef {import("@webassemblyjs/ast").ModuleImportDescription} ModuleImportDescription */
class WebAssemblyImportDependency extends ModuleDependency {
/**
* @param {string} request the request
* @param {string} name the imported name
* @param {ModuleImportDescription} description the WASM ast node
* @param {false | string} onlyDirectImport if only direct imports are allowed
*/
constructor(request, name, description, onlyDirectImport) {
super(request);
/** @type {string} */
this.name = name;
/** @type {TODO} */
/** @type {ModuleImportDescription} */
this.description = description;
/** @type {false | string} */
this.onlyDirectImport = onlyDirectImport;