Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: remove preprocessor-specific attributes#653

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
dummdidumm wants to merge2 commits intomain
base:main
Choose a base branch
Loading
fromremove-attributes
Open
Show file tree
Hide file tree
Changes fromall 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
3 changes: 2 additions & 1 deletiondocs/preprocessing.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -123,8 +123,9 @@ export default {
/** Add a custom language preprocessor */
potatoLanguage({ content, filename, attributes }) {
const { code, map } = require('potato-language').render(content);
const { src, ...cleanedAttributes } = attributes;
Copy link
Member

Choose a reason for hiding this comment

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

this example does not make sense as i assume potato-language uses the lang attribute value.

If you want to show it here, the preprocessor would have to use a custompotato attribute that then gets filtered


return { code, map };
return { code, map, attributes: cleanedAttributes };
},
}),
}),
Expand Down
6 changes: 6 additions & 0 deletionssrc/modules/tagInfo.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -67,3 +67,9 @@ export const getTagInfo = async ({
markup,
};
};

export const removeSrcAttribute = (attributes: Record<string, any>) => {
Copy link
Member

@dominikgdominikgAug 28, 2024
edited
Loading

Choose a reason for hiding this comment

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

should this be a generic util?

exportconstfilterAttributes(attributes:Record<string,any>,filterFn:(a:string)=>boolean){returnObject.fromEntries(Object.entries(attributes).filter(([a])=>filterFn(a)))}

usage:

constcleanAttributes=filterAttributes(attributes,a=>a!=='src');// orconstattributesToRemove=['foo','bar'];constcleanMultipleAttributes=filterAttributes(attributes,a=>!attributesToRemove.includes(a))

that can be reused for global and potentially others?

const { src, ...rest } = attributes;

return rest;
};
3 changes: 2 additions & 1 deletionsrc/processors/babel.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import { concat } from '../modules/utils';
import { getTagInfo } from '../modules/tagInfo';
import { getTagInfo, removeSrcAttribute } from '../modules/tagInfo';
import { prepareContent } from '../modules/prepareContent';

import type { PreprocessorGroup, Options } from '../types';
Expand All@@ -22,6 +22,7 @@ const babel = (options?: Options.Babel): PreprocessorGroup => ({

return {
...transformed,
attributes: removeSrcAttribute(transformed.attributes || attributes),
dependencies: concat(dependencies, transformed.dependencies),
};
},
Expand Down
3 changes: 2 additions & 1 deletionsrc/processors/coffeescript.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { getTagInfo } from '../modules/tagInfo';
import { getTagInfo, removeSrcAttribute } from '../modules/tagInfo';
import { concat } from '../modules/utils';
import { prepareContent } from '../modules/prepareContent';

Expand DownExpand Up@@ -32,6 +32,7 @@ const coffeescript = (options?: Options.Coffeescript): PreprocessorGroup => ({

return {
...transformed,
attributes: removeSrcAttribute(transformed.attributes || attributes),
dependencies: concat(dependencies, transformed.dependencies),
};
},
Expand Down
3 changes: 2 additions & 1 deletionsrc/processors/less.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { getTagInfo } from '../modules/tagInfo';
import { getTagInfo, removeSrcAttribute } from '../modules/tagInfo';
import { concat } from '../modules/utils';
import { prepareContent } from '../modules/prepareContent';

Expand All@@ -25,6 +25,7 @@ const less = (options?: Options.Less): PreprocessorGroup => ({

return {
...transformed,
attributes: removeSrcAttribute(transformed.attributes || attributes),
dependencies: concat(dependencies, transformed.dependencies),
};
},
Expand Down
3 changes: 2 additions & 1 deletionsrc/processors/postcss.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { getTagInfo } from '../modules/tagInfo';
import { getTagInfo, removeSrcAttribute } from '../modules/tagInfo';
import { concat } from '../modules/utils';
import { prepareContent } from '../modules/prepareContent';

Expand All@@ -23,6 +23,7 @@ const postcss = (options?: Options.Postcss): PreprocessorGroup => ({

return {
...transformed,
attributes: removeSrcAttribute(transformed.attributes || attributes),
dependencies: concat(dependencies, transformed.dependencies),
};
},
Expand Down
3 changes: 2 additions & 1 deletionsrc/processors/scss.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { getTagInfo } from '../modules/tagInfo';
import { getTagInfo, removeSrcAttribute } from '../modules/tagInfo';
import { concat } from '../modules/utils';
import { prepareContent } from '../modules/prepareContent';

Expand DownExpand Up@@ -33,6 +33,7 @@ const scss = (options?: Options.Sass): PreprocessorGroup => ({

return {
...transformed,
attributes: removeSrcAttribute(transformed.attributes || attributes),
dependencies: concat(dependencies, transformed.dependencies),
};
},
Expand Down
3 changes: 2 additions & 1 deletionsrc/processors/stylus.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { getTagInfo } from '../modules/tagInfo';
import { getTagInfo, removeSrcAttribute } from '../modules/tagInfo';
import { concat } from '../modules/utils';
import { prepareContent } from '../modules/prepareContent';

Expand DownExpand Up@@ -31,6 +31,7 @@ const stylus = (options?: Options.Stylus): PreprocessorGroup => ({

return {
...transformed,
attributes: removeSrcAttribute(transformed.attributes || attributes),
dependencies: concat(dependencies, transformed.dependencies),
};
},
Expand Down
3 changes: 2 additions & 1 deletionsrc/processors/typescript.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { getTagInfo } from '../modules/tagInfo';
import { getTagInfo, removeSrcAttribute } from '../modules/tagInfo';
import { concat } from '../modules/utils';
import { prepareContent } from '../modules/prepareContent';

Expand DownExpand Up@@ -26,6 +26,7 @@ const typescript = (options?: Options.Typescript): PreprocessorGroup => ({

return {
...transformed,
attributes: removeSrcAttribute(transformed.attributes || attributes),
dependencies: concat(dependencies, transformed.dependencies),
};
},
Expand Down
12 changes: 11 additions & 1 deletionsrc/transformers/globalStyle.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -83,7 +83,17 @@ const transformer: Transformer<Options.GlobalStyle> = async ({
map: options?.sourceMap ? { prev: map } : false,
});

return { code: css, map: newMap };
if (attributes?.global) {
const { global, ...rest } = attributes;

attributes = rest;
}

return {
code: css,
map: newMap,
attributes,
};
};

export { transformer };
2 changes: 1 addition & 1 deletiontest/processors/babel.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,7 @@ describe(`processor - babel`, () => {
]);

expect(preprocessed.toString?.()).toMatchInlineSnapshot(`
"<script src="./fixtures/script.babel.js">export var hello = {};
"<script>export var hello = {};
export var world = hello == null ? void 0 : hello.value;</script><div></div>"
`);
});
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp