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

Crashing on a single Typescript file #1359

Closed
oyatek opened this issue Mar 5, 2021 · 6 comments
Closed

Crashing on a single Typescript file #1359

oyatek opened this issue Mar 5, 2021 · 6 comments
Assignees

Comments

@oyatek
Copy link

oyatek commented Mar 5, 2021

documentation.js version: 12.3.0

command:

documentation build ./wp-content/plugins/mapsvg-dev/js/mapsvg/Map/Map.ts --parse-extension ts -f html -o ./docs/api-v6 --theme ./documentation-theme-light/ --sort-order alpha

Result:

SyntaxError: Unexpected token, expected "}" (305:30)
    at _class.raise (/usr/local/lib/node_modules/documentation/node_modules/@babel/parser/lib/index.js:3939:15)
    at _class.unexpected (/usr/local/lib/node_modules/documentation/node_modules/@babel/parser/lib/index.js:5248:16)
    at _class.expect (/usr/local/lib/node_modules/documentation/node_modules/@babel/parser/lib/index.js:5236:28)
    at _class.jsxParseExpressionContainer (/usr/local/lib/node_modules/documentation/node_modules/@babel/parser/lib/index.js:3497:12)
    at _class.jsxParseElementAt (/usr/local/lib/node_modules/documentation/node_modules/@babel/parser/lib/index.js:3584:36)
    at _class.jsxParseElement (/usr/local/lib/node_modules/documentation/node_modules/@babel/parser/lib/index.js:3626:19)
    at _class.parseExprAtom (/usr/local/lib/node_modules/documentation/node_modules/@babel/parser/lib/index.js:3633:21)
    at _class.parseExprSubscripts (/usr/local/lib/node_modules/documentation/node_modules/@babel/parser/lib/index.js:5924:21)
    at _class.parseMaybeUnary (/usr/local/lib/node_modules/documentation/node_modules/@babel/parser/lib/index.js:5903:21)
    at _class.parseMaybeUnary (/usr/local/lib/node_modules/documentation/node_modules/@babel/parser/lib/index.js:10244:54)

The code at line 305 in Map.ts:

this.editRegions = {on:false};

The error points to column number 30 which is the letter "o" after "{". Somehow babel doesn't like the on:false content and wants to see an empty object instead: {}. Why?

The editRegions property is defined above in the same file as:

editRegions: {on: boolean};
@oyatek
Copy link
Author

oyatek commented Mar 12, 2021

Please somebody shed some light on this. We need to generate documentation for our software.

@tmcw
Copy link
Member

tmcw commented Mar 12, 2021

Can you share more of the surrounding code? This small snippet looks fine, and likely isn't the problem. It's most likely something like an unsupported syntax that's in the code before this.

@oyatek
Copy link
Author

oyatek commented Mar 23, 2021

@tmcw thank you for your reply. The code before that line:

constructor(
        containerId: string,
        mapParams: {
            id: number;
            options: MapOptionsInterface;
            svgFileLastChanged: number;
            version: string;
        }
    ) {
        const options = mapParams.options;

        this.updateOutdatedOptions(options);

        this.dirtyFields = [];

        this.containerId = containerId;
        this.options = <MapOptionsInterface>$.extend(true, {}, DefaultOptions, options);

        this.options.source = this.urlToRelativePath(this.options.source);

        this.editMode = this.options.editMode;
        delete this.options.editMode;

        this.id = mapParams.id;
        this.svgFileLastChanged = mapParams.svgFileLastChanged;

        this.regions = new ArrayIndexed("id");
        this.objects = new ArrayIndexed("id");

        this.events = new Events(this);

        this.highlightedRegions = [];
        this.editRegions = { on: false }; // <<<<<< COMPILER CRASHES HERE
        
        ```

@tmcw
Copy link
Member

tmcw commented Mar 23, 2021

Here's a reduced testcase:

https://astexplorer.net/#/gist/9bfc7aabbd7d0db836fe9ebe4c0b6fe4/885f6051fe9c4804293bf8a20b0a83991e1ed736

The bad line is

this.options = <MapOptionsInterface>$.extend(true, {}, DefaultOptions, options);

So the issue is, per the TypeScript playground, that this file will not work if JSX is enabled in the TS config. Switching that on and off might be an option if that's a PR to documentation.js, or there may be a different way to express that typing that doesn't trigger JSX.

@oyatek
Copy link
Author

oyatek commented Mar 26, 2021

@tmcw you saved my life, thank you so much :) I would never find that by myself. I'll try to disable JSX now.

@oyatek
Copy link
Author

oyatek commented Mar 26, 2021

So how can I disable JSX for documentation.js/TS parser? I've tried adding the following line to tsconfig.js but it didn't help:

"jsx": "preserve"

Docs: https://www.typescriptlang.org/tsconfig#jsx
Does the TS parser triggered by documentation.js search for tsconfig file?

anthony-redFox added a commit to anthony-redFox/documentation that referenced this issue Apr 22, 2021
…ntationjs#1359

ts has conflict syntax with casting type. It is valid TS but not valid TSX
@anthony-redFox anthony-redFox self-assigned this Apr 22, 2021
@tmcw tmcw closed this as completed in 00d434f Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants