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(vue): not filter rpx when parse style #4148

Merged
merged 1 commit into from
Dec 9, 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
4 changes: 4 additions & 0 deletions driver/js/packages/hippy-vue-css-loader/src/css-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,15 @@
if (Number.isInteger(value)) {
return value;
}
// If value unit is rpx, don't need to filter
if (typeof value === 'string' && value.endsWith('rpx')) {
return value;
}
// If value unit is px, change to use pt as 1:1.
if (typeof value === 'string' && value.endsWith('px')) {
const num = parseFloat(value.slice(0, value.indexOf('px')));
if (!Number.isNaN(num)) {
value = num;

Check warning on line 110 in driver/js/packages/hippy-vue-css-loader/src/css-parser.ts

View workflow job for this annotation

GitHub Actions / frontend_build_tests (16.x)

Assignment to function parameter 'value'

Check warning on line 110 in driver/js/packages/hippy-vue-css-loader/src/css-parser.ts

View workflow job for this annotation

GitHub Actions / frontend_build_tests (17.x)

Assignment to function parameter 'value'
}
}
return value;
Expand All @@ -113,7 +117,7 @@
* Parse the CSS to be AST tree.
*/
function parseCSS(css: any, options: any) {
options = options || {};

Check warning on line 120 in driver/js/packages/hippy-vue-css-loader/src/css-parser.ts

View workflow job for this annotation

GitHub Actions / frontend_build_tests (16.x)

Assignment to function parameter 'options'

Check warning on line 120 in driver/js/packages/hippy-vue-css-loader/src/css-parser.ts

View workflow job for this annotation

GitHub Actions / frontend_build_tests (17.x)

Assignment to function parameter 'options'

/**
* Positional.
Expand All @@ -137,7 +141,7 @@
function position() {
const start = { line: lineno, column };
return (node: any) => {
node.position = new Position(start);

Check warning on line 144 in driver/js/packages/hippy-vue-css-loader/src/css-parser.ts

View workflow job for this annotation

GitHub Actions / frontend_build_tests (16.x)

Assignment to property of function parameter 'node'

Check warning on line 144 in driver/js/packages/hippy-vue-css-loader/src/css-parser.ts

View workflow job for this annotation

GitHub Actions / frontend_build_tests (17.x)

Assignment to property of function parameter 'node'
whitespace();
return node;
};
Expand Down Expand Up @@ -235,7 +239,7 @@
}
const str = m[0];
updatePosition(str);
css = css.slice(str.length);

Check warning on line 242 in driver/js/packages/hippy-vue-css-loader/src/css-parser.ts

View workflow job for this annotation

GitHub Actions / frontend_build_tests (16.x)

Assignment to function parameter 'css'

Check warning on line 242 in driver/js/packages/hippy-vue-css-loader/src/css-parser.ts

View workflow job for this annotation

GitHub Actions / frontend_build_tests (17.x)

Assignment to function parameter 'css'
return m;
}

Expand All @@ -251,7 +255,7 @@
*/
function comments(rules: any[] = []): any[] {
let c;
rules = rules || [];

Check warning on line 258 in driver/js/packages/hippy-vue-css-loader/src/css-parser.ts

View workflow job for this annotation

GitHub Actions / frontend_build_tests (16.x)

Assignment to function parameter 'rules'

Check warning on line 258 in driver/js/packages/hippy-vue-css-loader/src/css-parser.ts

View workflow job for this annotation

GitHub Actions / frontend_build_tests (17.x)

Assignment to function parameter 'rules'
while ((c = comment()) !== null) {
if (c !== false) {
rules.push(c);
Expand Down Expand Up @@ -279,7 +283,7 @@
const str = css.slice(2, i - 2);
column += 2;
updatePosition(str);
css = css.slice(i);

Check warning on line 286 in driver/js/packages/hippy-vue-css-loader/src/css-parser.ts

View workflow job for this annotation

GitHub Actions / frontend_build_tests (16.x)

Assignment to function parameter 'css'

Check warning on line 286 in driver/js/packages/hippy-vue-css-loader/src/css-parser.ts

View workflow job for this annotation

GitHub Actions / frontend_build_tests (17.x)

Assignment to function parameter 'css'
column += 2;
return pos({
type: 'comment',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ function convertPxUnitToPt(value) {
if (Number.isInteger(value)) {
return value;
}
// If value unit is rpx, don't need to filter
if (typeof value === 'string' && value.endsWith('rpx')) {
return value;
}
// If value unit is px, change to use pt as 1:1.
if (typeof value === 'string' && value.endsWith('px')) {
const num = parseFloat(value.slice(0, value.indexOf('px')));
Expand Down
Loading