我在 typescript 中有一个库,可以将一个类编译为 javascript:
ClassName = ClassName_1 = class ClassName{
...
}
ClassName = ClassName_1 = decorate([
...])
当我使用依赖于该库的 Angular 前端进行编译时,这会出现错误:
./node_modules/.bin/ng build --configuration=development --base-href /client/ --deploy-url /client/
给出以下错误:
ERROR in ./node_modules/library/ClassName.js
Module build failed: Error: Debug Failure. False expression.
我用打字稿编译所有东西,2.9.2因为它是一个 Angular 6 项目。我尝试7.0.0-rc使用 `3.0.3 但我仍然有这个错误,但我可能在这里有一个假阴性。
如果我手动更改 .js 文件,它可以工作:
ClassName = class ClassName{
...
}
ClassName_1 = ClassName
ClassName = ClassName_1 = decorate([
...])
ClassName_1 = ClassName
出现此错误的代码是:
/**
* Endpoint gives the baseDomain of MultiChat and gives the appropriate protocol.
* This is useful so you can pass through the same object to resources and streams types.
*
* A custom object is introduced to allow to pass the same object to use for WebSockets and https calls.
* Paths are also added to easily construct full routes.
*
* The design is to return full new objects so that you do not mix references.
*/
@injectable()
export class Endpoint {
public secure: boolean;
public baseDomain: string;
public paths: string[];
public port: number;
public queries: Map<string, string>;
/**
* init initializes the Endpoint with the correct baseDomain.
* @param secure is true if the _endpoint is reachable by HTTPS and WSS
* @param baseDomain the basedomain of the _endpoint, eg. independer.nl.
* @param paths additional paths to the _endpoint without slashes, eg. ["api"]
* @param port the port the _endpoint is hosted on
*/
constructor(secure: boolean, baseDomain: string, paths: string[] = [], port?: number) {
this.baseDomain = baseDomain;
this.paths = paths;
this.port = port;
this.secure = secure;
this.queries = new Map<string, string>();
}
/**
* addPath returns a new Endpoint object with the paths added and returns a clone of the Endpoint.
* @param paths
*/
public addPath(paths: string[]): Endpoint {
const result = this.cloneEndpoint();
result.paths = this.paths.concat(paths);
return result;
}
/**
* addQuery adds a new query parameter and returns a clone of the Endpoint.
* @param key The key of the parameter.
* @param value The value of the parameter.
*/
public addQuery(key: string, value: string): Endpoint {
const result = this.cloneEndpoint();
result.queries.set(key, value);
return result;
}
/**
* getHTTP returns the HTTP baseDomain string.
* If the baseDomain is secure it returns HTTPS.
*/
public getHTTP(): string {
const protocol = (this.secure ? "https" : "http");
return this.getEndpoint(protocol);
}
/**
* getWS returns the WebSocket baseDomain string.
* * If the baseDomain is secure it returns WSS.
*/
public getWS(): string {
const protocol = (this.secure ? "wss" : "ws");
return this.getEndpoint(protocol);
}
private cloneEndpoint(): Endpoint {
return new Endpoint(this.secure, this.baseDomain, this.paths, this.port);
}
private getEndpoint(protocol: string) {
const port = (this.port ? ":" + this.port : "");
let endpoint = protocol + "://" + this.baseDomain + port;
endpoint += this.getPath();
if (this.queries.size) {
endpoint += "?";
let first = true;
for (const key of this.queries.keys()) {
if (!first) {
endpoint += "&";
}
endpoint += key + "=" + encodeURIComponent(this.queries.get(key));
first = false;
}
}
return endpoint;
}
private getPath(): string {
let fullPath = "";
for (const path of this.paths) {
fullPath += "/" + path;
}
return fullPath;
}
}