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

deno 1.9.0 bundle (SyntaxError: A class may only have one constructor) #10252

Closed
iugo opened this issue Apr 19, 2021 · 3 comments
Closed

deno 1.9.0 bundle (SyntaxError: A class may only have one constructor) #10252

iugo opened this issue Apr 19, 2021 · 3 comments
Labels
fix available there is a fix available in a third party library that needs to be merged upstream Changes in upstream are required to solve these issues

Comments

@iugo
Copy link
Contributor

iugo commented Apr 19, 2021

with https://deno.land/x/postgres@v0.8.0/mod.ts

ts code is:

class Query {
  public text: string;
  public args: EncodedArg[];
  public fields?: string[];

  constructor(config: QueryObjectConfig);
  constructor(text: string, ...args: unknown[]);
  //deno-lint-ignore camelcase
  constructor(config_or_text: string | QueryObjectConfig, ...args: unknown[]) {
    let config: QueryConfig;
    if (typeof config_or_text === "string") {
      config = { text: config_or_text, args };
    } else {
      const {
        fields,
        //deno-lint-ignore camelcase
        ...query_config
      } = config_or_text;

      // Check that the fields passed are valid and can be used to map
      // the result of the query
      if (fields) {
        //deno-lint-ignore camelcase
        const clean_fields = fields.map((field) =>
          field.toString().toLowerCase()
        );

        if ((new Set(clean_fields)).size !== clean_fields.length) {
          throw new TypeError(
            "The fields provided for the query must be unique",
          );
        }

        this.fields = clean_fields;
      }

      config = query_config;
    }
    this.text = config.text;
    this.args = this._prepareArgs(config);
  }

  private _prepareArgs(config: QueryConfig): EncodedArg[] {
    const encodingFn = config.encoder ? config.encoder : encode;
    return (config.args || []).map(encodingFn);
  }
}

(1.9.0) deno bundle, code is:

class Query {
    text;
    args;
    fields;
    constructor(config2){
    }
    constructor(text, ...args2){
    }
    constructor(config_or_text, ...args1){
        let config1;
        if (typeof config_or_text === "string") {
            config1 = {
                text: config_or_text,
                args: args1
            };
        } else {
            const { fields: fields2 , ...query_config } = config_or_text;
            if (fields2) {
                const clean_fields = fields2.map((field)=>field.toString().toLowerCase()
                );
                if (new Set(clean_fields).size !== clean_fields.length) {
                    throw new TypeError("The fields provided for the query must be unique");
                }
                this.fields = clean_fields;
            }
            config1 = query_config;
        }
        this.text = config1.text;
        this.args = this._prepareArgs(config1);
    }
    _prepareArgs(config) {
        const encodingFn = config.encoder ? config.encoder : encode6;
        return (config.args || []).map(encodingFn);
    }
}

should (deno 1.8.2 is):

class Query {
    constructor(config_or_text, ...args1){
        let config1;
        if (typeof config_or_text === "string") {
            config1 = {
                text: config_or_text,
                args: args1
            };
        } else {
            const { fields: fields1 , ...query_config } = config_or_text;
            if (fields1) {
                const clean_fields = fields1.map((field)=>field.toString().toLowerCase()
                );
                if (new Set(clean_fields).size !== clean_fields.length) {
                    throw new TypeError("The fields provided for the query must be unique");
                }
                this.fields = clean_fields;
            }
            config1 = query_config;
        }
        this.text = config1.text;
        this.args = this._prepareArgs(config1);
    }
    _prepareArgs(config) {
        const encodingFn = config.encoder ? config.encoder : encode6;
        return (config.args || []).map(encodingFn);
    }
}
@iugo
Copy link
Contributor Author

iugo commented Apr 19, 2021

https://www.typescriptlang.org/play?#code/MYGwhgzhAECKCuBTATgT2gbwFDWsA9gHYQAuy8wJ+yAFAYQGYCWA5gFzSHwC2ARigEoA3DjxFS5StRolEADxIcJTQiwA00AHTawyFhA7xCAa0L4A7oQDaAXWGj6EilVr1mLAPrUPshUrIqLNAAPpw8-Mga2pq6+oYmZpa2ApiiAL5YGUA

class Query {
  constructor(config: number);
  constructor(text: string, ...args: unknown[]);
  constructor(config_or_text: string | number, ...args: unknown[]) {
  }
}
"use strict";
class Query {
    constructor(config_or_text, ...args) {
    }
}

@Liamolucko
Copy link
Contributor

It looks like this is fixed on swc master, so this should be solved by an swc upgrade.

@lucacasonato lucacasonato added fix available there is a fix available in a third party library that needs to be merged upstream Changes in upstream are required to solve these issues labels Apr 19, 2021
@disyam
Copy link

disyam commented Apr 29, 2021

looks like this is fixed on 1.9.2

@iugo iugo closed this as completed Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix available there is a fix available in a third party library that needs to be merged upstream Changes in upstream are required to solve these issues
Projects
None yet
Development

No branches or pull requests

4 participants