-
Notifications
You must be signed in to change notification settings - Fork 7
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
Improve options validation #29
Comments
I started implementing the options validation in a new branch.
Btw, thank you @alexprey for being really responsive and friendly, it's has been great collaborating with you, and I hope it continues. |
@soft-decay thanks for taking this task!
Thanks you too for collaboration, I very appreciate your interest in this project! |
Quick question. In if (options.structure) {
return options.structure;
} for the presence of a content?: string;
template?: string;
scripts?: unknown[];
styles?: unknown[]; but I did not find where structure was assigned to options. In
but then structure and options are passed around together. Is it ok if I do:
then remove |
This can be used when code of component was already splitted, f.ex. when we use a svelte preprocessor or webpack plugin we have already splitted content. |
Ok, I decided to assign directly to // file: lib/v3/parser.js
- constructor(structure, options) {
+ constructor(options) {
super();
this._options = Object.assign({}, DEFAULT_OPTIONS, options);
- this.structure = structure;
+ this.structure = options.structure; |
I created pull request #44 for this. I might have gone a little overboard with the options typings, but now there is pretty good autocompletion and type checking for the options object. I also documented the main parse function with a usage example. I added basic tests for options, but maybe something more exhaustive is required. |
feat(options): Validate options passed to the parse function (#29)
I think the next step is to start validating parser specific options (inside each parser). I checked what is already validated, and each parser uses a different approach:
v2-parser: ConstructorA lot of things seem to be outdated here. What to do with these : this.defaultMethodVisibility = options.defaultMethodVisibility;
this.defaultActionVisibility = options.defaultActionVisibility; They don't exist in It seems the DEFAULT_OPTIONS are for the espree parser, but they are assigned to the same options object. Maybe build a separate v3-parser: ConstructorThis is not used :
Todov2-parser:
v3-parser:
|
In the v2-parser constructor: try {
// try with default options { loc: undefined, range: false, comment: undefined }
} catch (e) {
const script = utils.escapeImportKeyword(options.source.script);
// try again with { loc: true, range: true, comment: true }
} Is there a reason for this. Wouldn't it be better to set the default values to There is also this block : if (this.ast === null) {
if (this.features.includes('name')) {
this.parseComponentName();
}
return this.emit('end');
} The check for feature 'name' should be out of the block I think. It also appears at the end of |
Not sure that the whole block should be wrapped by feature check, because the end event should be always emitted when parsing are done |
I just meant to do this: if (this.features.includes('name')) {
this.parseComponentName();
}
if (this.ast === null) {
return this.emit('end');
} and remove the same check present at the end of In all cases, I think I'll start putting my efforts on parser-v3 instead. It's the current version of svelte so it's probably the most used. |
…tChaotic#29) - refactor: move features validation to lib/options - refactor: move ast options to lib/options - test: Add tests for options.validateFeatures - test: Add integration test for features validation
…ers-options feat(options): Improve validation for parsers internal options (#29)
At this point not all option parameters validated by the code. It will be nice to add checks for all options.
The text was updated successfully, but these errors were encountered: