Skip to content

Commit 04fdc14

Browse files
authored
Implement ignore locations option (#92)
* Implement ignore locations option * Fix types for plugin-rollup * Fix Webpack types * Cleanup root rollup.config.mjs (keep comments aswell for easier debugging) * Release new transpiler * publish transpiler/rollup/webpack
1 parent 1f5b55e commit 04fdc14

File tree

10 files changed

+38
-32
lines changed

10 files changed

+38
-32
lines changed

@runtime-type-inspector/transpiler/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "@runtime-type-inspector/transpiler",
3-
"version": "2.2.2",
3+
"version": "2.2.5",
44
"description": "Validating JSDoc types at runtime for high-quality types - Trust is good, control is better.",
55
"main": "index.cjs",
66
"module": "index.mjs",
7-
"types": "types.d.ts",
7+
"types": "index.mjs",
88
"repository": {
99
"type": "git",
1010
"url": "git+https://github.com/kungfooman/RuntimeTypeInspector.js.git"
@@ -17,7 +17,7 @@
1717
"type": "module",
1818
"homepage": "https://github.com/kungfooman/RuntimeTypeInspector.js#readme",
1919
"dependencies": {
20-
"@babel/core": "^7.2.0",
20+
"@babel/parser": "^7.23.0",
2121
"@runtime-type-inspector/runtime": "^2.1.0",
2222
"typescript": "^5.1.6"
2323
},

plugin-rollup/index.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ import {
33
addTypeChecks, expandType, compareAST, code2ast2code
44
} from '@runtime-type-inspector/transpiler';
55
/**
6-
* @typedef Options
6+
* @typedef OptionsProps
77
* @property {boolean} [enable] - Enable or disable entire plugin. Defaults to true.
88
* @property {boolean} [selftest] - Every once in a while Babel changes the AST, so we
99
* self-test Stringifier class to ensure its functionanlity.
1010
* @property {string[]} [ignoredFiles] - Ignore certain files which operate in a different
1111
* context, for example framework/parsers/draco-worker.js operates as WebWorker (without RTI).
1212
* @property {boolean} [validateDivision] - Whether divisions are validated. Defaults to true.
1313
*/
14+
/**
15+
* @typedef {OptionsProps & import('@runtime-type-inspector/transpiler').Options} Options
16+
*/
1417
/**
1518
* @param {Options} [options] - Optional options.
1619
* @returns {import('rollup').Plugin} The rollup plugin.
1720
*/
18-
function runtimeTypeInspector({enable = true, selftest = false, ignoredFiles, validateDivision = true} = {}) {
21+
function runtimeTypeInspector({enable = true, selftest = false, ignoredFiles, ...options} = {}) {
1922
const filter = createFilter([
2023
'**/*.js'
2124
], []);
@@ -37,10 +40,9 @@ function runtimeTypeInspector({enable = true, selftest = false, ignoredFiles, va
3740
}
3841
// todo expose options to rollup plugin
3942
code = addTypeChecks(code, {
40-
validateDivision,
41-
// ignoreLocations: ['Tensor#constructor'], // todo
4243
expandType,
4344
filename: id,
45+
...options
4446
});
4547
return {
4648
code,

plugin-rollup/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "@runtime-type-inspector/plugin-rollup",
3-
"version": "1.2.2",
3+
"version": "1.2.3",
44
"description": "Rollup plugin for https://runtimetypeinspector.org/",
55
"main": "index.mjs",
66
"type": "module",
7-
"types": "types.d.ts",
7+
"types": "index.mjs",
88
"author": "Hermann Rolfes (kungfooman)",
99
"license": "MIT",
1010
"dependencies": {
11-
"@runtime-type-inspector/transpiler": "^2.2.2",
11+
"@runtime-type-inspector/transpiler": "^2.2.5",
1212
"rollup": "^3.29.4"
1313
}
1414
}

plugin-rollup/types.d.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

plugin-webpack4/index.cjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
const {Compilation, Compiler} = require('webpack');
22
/**
3-
* @typedef RuntimeTypeInspectorPluginOptions
3+
* @typedef OptionsProps
44
* @property {RegExp} [test] - Test for file extensions.
55
* @property {RegExp} [exclude] - Test for exclusion.
66
*/
7+
/**
8+
* @typedef {OptionsProps & import('@runtime-type-inspector/transpiler').Options} Options
9+
*/
710
class RuntimeTypeInspectorPlugin {
811
static pluginName = 'RuntimeTypeInspectorPlugin';
912
// Default options
@@ -14,7 +17,7 @@ class RuntimeTypeInspectorPlugin {
1417
exclude: /node_modules/
1518
};
1619
/**
17-
* @param {RuntimeTypeInspectorPluginOptions} options - The options.
20+
* @param {Options} options - The options.
1821
*/
1922
constructor(options) {
2023
Object.assign(this.options, options);

plugin-webpack4/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "@runtime-type-inspector/plugin-webpack4",
3-
"version": "1.2.3",
3+
"version": "1.2.4",
44
"description": "Webpack 4 plugin for https://runtimetypeinspector.org/",
55
"main": "index.cjs",
66
"author": "Hermann Rolfes (kungfooman)",
77
"license": "MIT",
88
"dependencies": {
9-
"@runtime-type-inspector/transpiler": "^2.2.2",
9+
"@runtime-type-inspector/transpiler": "^2.2.5",
1010
"loader-utils": "^2.0.4",
1111
"webpack": "^4.47.0"
1212
}

plugin-webpack5/index.cjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
const {Compilation, Compiler} = require('webpack');
22
/**
3-
* @typedef RuntimeTypeInspectorPluginOptions
3+
* @typedef OptionsProps
44
* @property {RegExp} [test] - Test for file extensions.
55
* @property {RegExp} [exclude] - Test for exclusion.
66
*/
7+
/**
8+
* @typedef {OptionsProps & import('@runtime-type-inspector/transpiler').Options} Options
9+
*/
710
class RuntimeTypeInspectorPlugin {
811
static pluginName = 'RuntimeTypeInspectorPlugin';
912
// Default options
@@ -14,7 +17,7 @@ class RuntimeTypeInspectorPlugin {
1417
exclude: /node_modules/
1518
};
1619
/**
17-
* @param {RuntimeTypeInspectorPluginOptions} options - The options.
20+
* @param {Options} options - The options.
1821
*/
1922
constructor(options) {
2023
Object.assign(this.options, options);

plugin-webpack5/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "@runtime-type-inspector/plugin-webpack5",
3-
"version": "1.2.3",
3+
"version": "1.2.4",
44
"description": "Webpack 5 plugin for https://runtimetypeinspector.org/",
55
"main": "index.cjs",
66
"author": "Hermann Rolfes (kungfooman)",
77
"license": "MIT",
88
"dependencies": {
9-
"@runtime-type-inspector/transpiler": "^2.2.2",
9+
"@runtime-type-inspector/transpiler": "^2.2.5",
1010
"loader-utils": "^2.0.4",
1111
"webpack": "^5.89.0"
1212
}

rollup.config.mjs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,18 @@ import json from '@rollup/plugin-json';
1313
//import {addTypeChecks} from "./src-transpiler/typeInserter.mjs";
1414
//const {addTypeChecks} = await import("runtime-type-inspector/src-transpiler/typeInserter.mjs");
1515
import commonjs from '@rollup/plugin-commonjs';
16-
//import {runtimeTypeInspector} from './plugin-rollup/index.mjs';
1716
/** @typedef {import('rollup').RollupOptions} RollupOptions */
1817
/** @typedef {import('rollup').Plugin} Plugin */
1918
/** @typedef {import('rollup').OutputOptions} OutputOptions */
2019
/** @typedef {import('@rollup/plugin-babel').RollupBabelInputPluginOptions} RollupBabelInputPluginOptions */
2120
/**
2221
* The ES5 options for babel(...) plugin.
23-
*
24-
* @param {string} buildType - Only 'debug' requires special handling so far.
2522
* @returns {RollupBabelInputPluginOptions} The babel options.
2623
*/
27-
const es5Options = buildType => ({
24+
const es5Options = () => ({
2825
babelHelpers: 'bundled',
2926
babelrc: false,
30-
comments: buildType === 'debug' || buildType === 'rti',
27+
comments: true,
3128
compact: false,
3229
minified: false,
3330
presets: [
@@ -44,14 +41,12 @@ const es5Options = buildType => ({
4441
});
4542
/**
4643
* The ES6 options for babel(...) plugin.
47-
*
48-
* @param {string} buildType - Only 'debug' requires special handling so far.
4944
* @returns {RollupBabelInputPluginOptions} The babel options.
5045
*/
51-
const moduleOptions = buildType => ({
46+
const moduleOptions = () => ({
5247
babelHelpers: 'bundled',
5348
babelrc: false,
54-
comments: buildType === 'debug',
49+
comments: true,
5550
compact: false,
5651
minified: false,
5752
presets: [
@@ -134,7 +129,7 @@ function buildTarget(name, rootFile, path, buildType, moduleFormat) {
134129
};
135130
const babelOptions = {
136131
es5: es5Options(buildType),
137-
es6: moduleOptions(buildType)
132+
es6: moduleOptions()
138133
};
139134
return {
140135
input: rootFile,

src-transpiler/Asserter.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {Stringifier } from './Stringifier.mjs';
1616
* @property {Function} [expandType] - A function that expands shorthand types into full descriptions.
1717
* @property {string} [filename] - The name of a file to which the instance pertains.
1818
* @property {boolean} [addHeader] - Whether to add import declarations headers. Defaults to true.
19+
* @property {string[]} [ignoreLocations] - Ignore these locations because they are known false-positives.
1920
*/
2021
class Asserter extends Stringifier {
2122
/**
@@ -27,6 +28,7 @@ class Asserter extends Stringifier {
2728
expandType = expandTypeDepFree,
2829
filename,
2930
addHeader = true,
31+
ignoreLocations = [],
3032
} = {}) {
3133
super();
3234
this.forceCurly = forceCurly;
@@ -36,6 +38,7 @@ class Asserter extends Stringifier {
3638
this.expandType = expandType;
3739
this.filename = filename;
3840
this.addHeader = addHeader;
41+
this.ignoreLocations = ignoreLocations;
3942
}
4043
/** @type {Record<string, Stat>} */
4144
stats = {
@@ -389,6 +392,10 @@ class Asserter extends Stringifier {
389392
const {spaces} = this;
390393
let out = '';
391394
let first = true;
395+
const loc = this.getName(node);
396+
if (this.ignoreLocations.includes(loc)) {
397+
return '// IGNORE RTI TYPE VALIDATIONS, KNOWN ISSUES\n';
398+
}
392399
//out += `${spaces}/*${spaces} node.type=${node.type}\n${spaces}
393400
// ${JSON.stringify(jsdoc)}\n${parent}\n${spaces}*/\n`;
394401
for (let name in jsdoc) {

0 commit comments

Comments
 (0)