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

feat: script attributes #282

Merged
merged 13 commits into from
Jun 11, 2021
Merged

feat: script attributes #282

merged 13 commits into from
Jun 11, 2021

Conversation

maoxiaoke
Copy link
Collaborator

Closes #276

@maoxiaoke maoxiaoke changed the title feat: script attributes [WIP]feat: script attributes Apr 8, 2021
@maoxiaoke maoxiaoke changed the title [WIP]feat: script attributes feat: script attributes May 18, 2021
@maoxiaoke maoxiaoke requested a review from ClarkXia May 18, 2021 06:59
@maoxiaoke maoxiaoke changed the title feat: script attributes [WIP]feat: script attributes May 20, 2021
@maoxiaoke
Copy link
Collaborator Author

hold on, rfc review required.

@maoxiaoke maoxiaoke changed the base branch from master to release/2.4.0 June 7, 2021 05:51
@maoxiaoke maoxiaoke changed the title [WIP]feat: script attributes feat: script attributes Jun 7, 2021
src/util/handleAssets.ts Outdated Show resolved Hide resolved
src/util/handleAssets.ts Outdated Show resolved Hide resolved
src/util/helpers.ts Show resolved Hide resolved
@maoxiaoke maoxiaoke requested a review from ClarkXia June 7, 2021 12:27
@maoxiaoke maoxiaoke requested review from SoloJiang and removed request for FuzzyFade June 9, 2021 12:05
attrs.forEach(attr => {
const [attrKey, attrValue] = attr.split('=');
if (unableReachedAttributes.includes(attrKey)) {
(isDev ? console.warn : console.log)(formatMessage(`${attrKey} will be ignored by icestark.`));

Choose a reason for hiding this comment

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

提示写反了

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

* script.crossOrigin = 'use-credentials';
* sscript.noModule = false;
*/
element[builtInScriptAttributesMap.get(attrKey)] = (attrValue === 'true' || attrValue === 'false' || !attrValue) ? !!attrValue : attrValue;

Choose a reason for hiding this comment

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

这段逻辑有点问题,字符串 false,取 !!true

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

* script.crossOrigin = 'use-credentials';
* script.noModule = true;
*/
const nonLooseBooleanAttrValue = (attrValue === 'true' || attrValue === 'false') ? Boolean(attrValue) : attrValue;
Copy link
Member

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...

Copy link
Member

Choose a reason for hiding this comment

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

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

* script.noModule = true;
*/
const nonLooseBooleanAttrValue = (attrValue === 'true' || attrValue === 'false') ? Boolean(attrValue) : attrValue;
element[builtInScriptAttributesMap.get(attrKey)] = nonLooseBooleanAttrValue === undefined ? true : attrValue;
Copy link
Member

Choose a reason for hiding this comment

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

而且这里也可以直接用 || 来写...

Copy link
Collaborator Author

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 均为有效值

Copy link
Member

@FuzzyFade FuzzyFade Jun 11, 2021

Choose a reason for hiding this comment

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

我的意思是 167 行可以这样写:nonLooseBooleanAttrValue === undefined || attrValue 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@maoxiaoke maoxiaoke merged commit 5b974aa into release/2.4.0 Jun 11, 2021
@delete-merged-branch delete-merged-branch bot deleted the feat/scriptAttributes branch June 11, 2021 07:26
maoxiaoke added a commit that referenced this pull request Jun 16, 2021
* fix: 🐛 error component render error (#313)

* fix: 🐛 unexpectable sandbox's cleaning up when load module (#311)

* feat: script attributes (#282)

* test: 💍 fix slient pass (#315)

* feat: 🎸 support symbol key for index (#316)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

支持 script 增加额外的 attributes,比如 crossorigin
4 participants