-
Notifications
You must be signed in to change notification settings - Fork 173
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
feat: script attributes #282
Conversation
hold on, rfc review required. |
attrs.forEach(attr => { | ||
const [attrKey, attrValue] = attr.split('='); | ||
if (unableReachedAttributes.includes(attrKey)) { | ||
(isDev ? console.warn : console.log)(formatMessage(`${attrKey} will be ignored by icestark.`)); |
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.
提示写反了
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.
done
src/util/handleAssets.ts
Outdated
* script.crossOrigin = 'use-credentials'; | ||
* sscript.noModule = false; | ||
*/ | ||
element[builtInScriptAttributesMap.get(attrKey)] = (attrValue === 'true' || attrValue === 'false' || !attrValue) ? !!attrValue : attrValue; |
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.
这段逻辑有点问题,字符串 false
,取 !!
是 true
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.
done
src/util/handleAssets.ts
Outdated
* script.crossOrigin = 'use-credentials'; | ||
* script.noModule = true; | ||
*/ | ||
const nonLooseBooleanAttrValue = (attrValue === 'true' || attrValue === 'false') ? Boolean(attrValue) : attrValue; |
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.
好像可以直接改写成 attrValue === 'true' || attrValue === 'false' || attrValue
因为在该条件下 Boolean(attrValue) 永远返回 true...
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.
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.
done
src/util/handleAssets.ts
Outdated
* script.noModule = true; | ||
*/ | ||
const nonLooseBooleanAttrValue = (attrValue === 'true' || attrValue === 'false') ? Boolean(attrValue) : attrValue; | ||
element[builtInScriptAttributesMap.get(attrKey)] = nonLooseBooleanAttrValue === undefined ? true : attrValue; |
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.
而且这里也可以直接用 || 来写...
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.
|| 的逻辑是前面是 falsy value, 这里只判断 undefined,其他 falsy value 均为有效值
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.
我的意思是 167 行可以这样写:nonLooseBooleanAttrValue === undefined || attrValue 😄
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.
done
Closes #276