@playcanvas/attribute-parser 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* These types are use to extend the global types in the program being parsed.
|
|
3
|
+
* It's useful to add types to modules that are not written in TypeScript.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// This allows http/s modules to be imported without TypeScript errors
|
|
7
|
+
|
|
8
|
+
export default `
|
|
9
|
+
declare module 'http://*' {
|
|
10
|
+
const value: any;
|
|
11
|
+
export default value;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module 'https://*' {
|
|
15
|
+
const value: any;
|
|
16
|
+
export default value;
|
|
17
|
+
}
|
|
18
|
+
`
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
2
|
import { createSystem, createDefaultMapFromNodeModules, createVirtualTypeScriptEnvironment } from '@typescript/vfs';
|
|
3
|
-
|
|
3
|
+
import globalTypes from './global.types.js';
|
|
4
4
|
import { ScriptParser } from './parsers/script-parser.js';
|
|
5
5
|
import { createDefaultMapFromCDN, flatMapAnyNodes, getExportedNodes, getType, inheritsFrom, isAliasedClassDeclaration } from './utils/ts-utils.js';
|
|
6
6
|
|
|
@@ -8,6 +8,7 @@ const toLowerCamelCase = str => str[0].toLowerCase() + str.substring(1);
|
|
|
8
8
|
|
|
9
9
|
const COMPILER_OPTIONS = {
|
|
10
10
|
strictPropertyInitialization: false, // Allow uninitialized properties
|
|
11
|
+
skipLibCheck: true, // Skip type checking of declaration files
|
|
11
12
|
target: ts.ScriptTarget.ES2022, // If this version changes, the types must be updated in the /rollup.config.mjs
|
|
12
13
|
module: ts.ModuleKind.CommonJS,
|
|
13
14
|
checkJs: true, // Enable JSDoc parsing
|
|
@@ -54,6 +55,9 @@ export class JSDocParser {
|
|
|
54
55
|
const system = createSystem(fsMap);
|
|
55
56
|
this._env = createVirtualTypeScriptEnvironment(system, Array.from(fsMap.keys()), ts, COMPILER_OPTIONS);
|
|
56
57
|
|
|
58
|
+
// Add global types to the parser
|
|
59
|
+
this._env.createFile('/global.d.ts', globalTypes);
|
|
60
|
+
|
|
57
61
|
return this;
|
|
58
62
|
}
|
|
59
63
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Script } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
// The parser should ignore https imports and not throw an error
|
|
4
|
+
import confetti from "https://esm.sh/canvas-confetti@1.6.0"
|
|
5
|
+
|
|
6
|
+
class Example extends Script {
|
|
7
|
+
/**
|
|
8
|
+
* @attribute
|
|
9
|
+
* @type {boolean}
|
|
10
|
+
*/
|
|
11
|
+
a = false;
|
|
12
|
+
|
|
13
|
+
initialize() {
|
|
14
|
+
confetti();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { Example };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* eslint-disable no-unused-expressions */
|
|
2
|
+
import { describe, it, before } from 'mocha';
|
|
3
|
+
import { expect } from 'chai';
|
|
4
|
+
|
|
5
|
+
import { parseAttributes } from '../../utils.js';
|
|
6
|
+
|
|
7
|
+
describe('VALID: Program ', function () {
|
|
8
|
+
let data;
|
|
9
|
+
before(async function () {
|
|
10
|
+
data = await parseAttributes('./program.valid.js');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('only results should exist', function () {
|
|
14
|
+
expect(data).to.exist;
|
|
15
|
+
expect(data[0]).to.not.be.empty;
|
|
16
|
+
expect(data[1]).to.be.empty;
|
|
17
|
+
});
|
|
18
|
+
});
|