Skip to content
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

chore: disallow optional chaining #10919

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export default tseslint.config(
message:
'Our output target is ES2016, so async/await syntax should be avoided.',
},
{
selector: 'ChainExpression',
message:
'Our output target is ES2016, and optional chaining results in ' +
'verbose helpers and should be avoided.',
},
],
'sort-imports': ['error', { ignoreDeclarationSort: true }],

Expand Down Expand Up @@ -134,7 +140,7 @@ export default tseslint.config(
{
files: [
'eslint.config.js',
'rollup.config.js',
'rollup*.config.js',
'scripts/**',
'./*.{js,ts}',
'packages/*/*.js',
Expand Down
2 changes: 2 additions & 0 deletions packages/compiler-core/src/babelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function walkIdentifiers(
}
} else if (
node.type === 'ObjectProperty' &&
// eslint-disable-next-line no-restricted-syntax
parent?.type === 'ObjectPattern'
) {
// mark property in destructure pattern
Expand Down Expand Up @@ -407,6 +408,7 @@ function isReferenced(node: Node, parent: Node, grandparent?: Node): boolean {
// no: export { NODE as foo } from "foo";
case 'ExportSpecifier':
// @ts-expect-error
// eslint-disable-next-line no-restricted-syntax
if (grandparent?.source) {
return false
}
Expand Down
2 changes: 2 additions & 0 deletions packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ export function trackEffect(
effect._depsLength++
}
if (__DEV__) {
// eslint-disable-next-line no-restricted-syntax
effect.onTrack?.(extend({ effect }, debuggerEventExtraInfo!))
}
}
Expand Down Expand Up @@ -309,6 +310,7 @@ export function triggerEffects(
(tracking ??= dep.get(effect) === effect._trackId)
) {
if (__DEV__) {
// eslint-disable-next-line no-restricted-syntax
effect.onTrigger?.(extend({ effect }, debuggerEventExtraInfo))
}
effect.trigger()
Expand Down
1 change: 1 addition & 0 deletions packages/runtime-core/src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function setDevtoolsHook(hook: DevtoolsHook, target: any) {
// some envs mock window but not fully
window.HTMLElement &&
// also exclude jsdom
// eslint-disable-next-line no-restricted-syntax
!window.navigator?.userAgent?.includes('jsdom')
) {
const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
Expand Down
5 changes: 5 additions & 0 deletions packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,11 +755,14 @@ function propHasMismatch(
}
}

// eslint-disable-next-line no-restricted-syntax
const root = instance?.subTree
if (
vnode === root ||
// eslint-disable-next-line no-restricted-syntax
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hydration code actually runs in the browser and shouldn't have been allowed

(root?.type === Fragment && (root.children as VNode[]).includes(vnode))
) {
// eslint-disable-next-line no-restricted-syntax
const cssVars = instance?.getCssVars?.()
for (const key in cssVars) {
expectedMap.set(`--${key}`, String(cssVars[key]))
Expand Down Expand Up @@ -840,7 +843,9 @@ function toStyleMap(str: string): Map<string, string> {
const styleMap: Map<string, string> = new Map()
for (const item of str.split(';')) {
let [key, value] = item.split(':')
// eslint-disable-next-line no-restricted-syntax
key = key?.trim()
// eslint-disable-next-line no-restricted-syntax
value = value?.trim()
if (key && value) {
styleMap.set(key, value)
Expand Down
1 change: 1 addition & 0 deletions packages/runtime-core/src/warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function warn(msg: string, ...args: any[]) {
instance,
ErrorCodes.APP_WARN_HANDLER,
[
// eslint-disable-next-line no-restricted-syntax
msg + args.map(a => a.toString?.() ?? JSON.stringify(a)).join(''),
instance && instance.proxy,
trace
Expand Down