-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(types): Add has|usingPlugin to typedef by adding stubs which are …
…removed from builds (#8811) ## Description tsc doesn't understand mixins and ignores jsdoc not followed by code. The jsdoc for the plugin methods `usingPlugin()` and `hasPlugin()` in Player are being ignored. To get them included in type outputs we need to have otherwise unnecessary stubs codes, as we already have for `on()` etc, which adds unnecessary, even if a small amount of, code to the outputs. ## Specific Changes proposed * Slight refactor of Player to include those stubs. * Adds a rollup plugin to delete lines between certain comments, so those stubs are deleted from the outputs. * Applies those comments to the `on()` etc stubs in Component and the new plugin stubs in Player. Any code surrounded by these comments, and the comments themselves, is deleted from the dist and test builds: ```js /* start-delete-from-build */ console.log('hi'); /* start-delete-from-build */ ``` Compared to main, video.min.js is 53 bytes smaller. ## Requirements Checklist - [ ] Feature implemented / Bug fixed - [ ] If necessary, more likely in a feature request than a bug fix - [ ] Change has been verified in an actual browser (Chrome, Firefox, IE) - [ ] Unit Tests updated or fixed - [ ] Docs/guides updated - [ ] Example created ([starter template on JSBin](https://codepen.io/gkatsev/pen/GwZegv?editors=1000#0)) - [ ] Has no DOM changes which impact accessiblilty or trigger warnings (e.g. Chrome issues tab) - [ ] Has no changes to JSDoc which cause `npm run docs:api` to error - [ ] Reviewed by Two Core Contributors
- Loading branch information
1 parent
3380d33
commit 820ef38
Showing
5 changed files
with
115 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Remove parts of files from outputs. Everything between a pair of `/* start-delete-from-build *\u002f` | ||
* and `/* end-delete-from-build *\u002f` comments | ||
* | ||
* Based on https://github.com/se-panfilov/rollup-plugin-strip-code | ||
*/ | ||
|
||
import { createFilter } from '@rollup/pluginutils'; | ||
|
||
const START_COMMENT = 'start-delete-from-build'; | ||
const END_COMMENT = 'end-delete-from-build'; | ||
|
||
/** | ||
* Remove lines of code surrounded by comments | ||
* | ||
* @param {Object} [options] Options | ||
* @param {string} [options.include] Files to inlcude | ||
* @param {string} [options.exclude] Files to exclude | ||
* @param {string} [options.startComment] Starting keywork, default start-delete-from-build | ||
* @param {string} [options.endComment] Eding keywork, default end-delete-from-build | ||
* @param {RegExp} [options.pattern] Custom regex | ||
* @return void | ||
*/ | ||
export default function excludeLines(options = {}) { | ||
// assume that the myPlugin accepts options of `options.include` and `options.exclude` | ||
const filter = createFilter(options.include, options.exclude); | ||
|
||
return { | ||
transform(code, id) { | ||
if (!filter(id)) { | ||
return; | ||
} | ||
|
||
const startComment = options.startComment || START_COMMENT; | ||
const endComment = options.endComment || END_COMMENT; | ||
const defaultPattern = new RegExp(`([\\t ]*\\/\\* ?${startComment} ?\\*\\/)[\\s\\S]*?(\\/\\* ?${endComment} ?\\*\\/[\\t ]*\\n?)`, 'g'); | ||
|
||
return code.replace(options.pattern || defaultPattern, ''); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters