-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Optimize EditorConfigProvider merging logic #40250
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,7 +78,7 @@ class EditorConfigProviderRegistry { | |
| current: EditorParamConfig, | ||
| merged: EditorParamConfig, | ||
| paramName: string | ||
| ): { fixedValue?: any; base?: number } { | ||
| ): { fixedValue: unknown } | { base: number } | {} { | ||
| if ( | ||
| this.isFixedParam(current) && | ||
| this.isFixedParam(merged) && | ||
|
|
@@ -128,37 +128,26 @@ class EditorConfigProviderRegistry { | |
| current: TimeIntervalParam, | ||
| merged: EditorParamConfig, | ||
| paramName: string | ||
| ): { timeBase?: string; default?: string } { | ||
| ): { timeBase: string; default: string } { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ The problem here was, that the method could from it's types return an object without |
||
| if (current.default !== current.timeBase) { | ||
| throw new Error(`Tried to provide differing default and timeBase values for ${paramName}.`); | ||
| } | ||
|
|
||
| if (this.isTimeBaseParam(current) && this.isTimeBaseParam(merged)) { | ||
| if (this.isTimeBaseParam(merged)) { | ||
| // In case both had where interval values, just use the least common multiple between both intervals | ||
| try { | ||
| const timeBase = leastCommonInterval(current.timeBase, merged.timeBase); | ||
| return { | ||
| default: timeBase, | ||
| timeBase, | ||
| }; | ||
| } catch (e) { | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| if (this.isTimeBaseParam(current)) { | ||
| try { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ I removed the redundant |
||
| parseEsInterval(current.timeBase); | ||
| return { | ||
| default: current.timeBase, | ||
| timeBase: current.timeBase, | ||
| }; | ||
| } catch (e) { | ||
| throw e; | ||
| } | ||
| const timeBase = leastCommonInterval(current.timeBase, merged.timeBase); | ||
| return { | ||
| default: timeBase, | ||
| timeBase, | ||
| }; | ||
| } | ||
|
|
||
| return {}; | ||
| // This code is simply here to throw an error in case the `timeBase` is not a valid ES interval | ||
| parseEsInterval(current.timeBase); | ||
| return { | ||
| default: current.timeBase, | ||
| timeBase: current.timeBase, | ||
| }; | ||
| } | ||
|
|
||
| private mergeConfigs(configs: EditorConfig[]): EditorConfig { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ We know this method is returning either of those, so we use a union type here instead, which makes more sense.