Skip to content

Commit

Permalink
incorrectly render time #10
Browse files Browse the repository at this point in the history
  • Loading branch information
tbela99 committed Aug 16, 2023
1 parent c3df4b6 commit a59a29d
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 41 deletions.
14 changes: 5 additions & 9 deletions dist/index-umd-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -1827,14 +1827,14 @@
}
}
if (val === '0') {
if (unit == 'Time') {
if (token.typ == 'Time') {
return '0s';
}
if (unit == 'Frequency') {
if (token.typ == 'Frequency') {
return '0Hz';
}
// @ts-ignore
if (unit == 'Resolution') {
if (token.typ == 'Resolution') {
return '0x';
}
return '0';
Expand Down Expand Up @@ -3886,10 +3886,6 @@
let tokens = results.map(mapToken);
let i;
let loc;
// if ((<Token>tokens.at(-1))?.typ == 'EOF') {
//
// tokens.pop();
// }
for (i = 0; i < tokens.length; i++) {
if (tokens[i].typ == 'Comment') {
// @ts-ignore
Expand Down Expand Up @@ -4706,14 +4702,14 @@
return fetch(resolve(url, currentFile).absolute).then(parseResponse);
}

function parse(iterator, opt = {}) {
async function parse(iterator, opt = {}) {
return parse$1(iterator, Object.assign(opt, {
load,
resolve,
cwd: opt.cwd ?? self.location.pathname.endsWith('/') ? self.location.pathname : dirname(self.location.pathname)
}));
}
function transform(css, options = {}) {
async function transform(css, options = {}) {
return transform$1(css, Object.assign(options, {
load,
resolve,
Expand Down
14 changes: 5 additions & 9 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1825,14 +1825,14 @@ function renderToken(token, options = {}, reducer) {
}
}
if (val === '0') {
if (unit == 'Time') {
if (token.typ == 'Time') {
return '0s';
}
if (unit == 'Frequency') {
if (token.typ == 'Frequency') {
return '0Hz';
}
// @ts-ignore
if (unit == 'Resolution') {
if (token.typ == 'Resolution') {
return '0x';
}
return '0';
Expand Down Expand Up @@ -3884,10 +3884,6 @@ async function parse$1(iterator, opt = {}) {
let tokens = results.map(mapToken);
let i;
let loc;
// if ((<Token>tokens.at(-1))?.typ == 'EOF') {
//
// tokens.pop();
// }
for (i = 0; i < tokens.length; i++) {
if (tokens[i].typ == 'Comment') {
// @ts-ignore
Expand Down Expand Up @@ -4698,10 +4694,10 @@ async function load(url, currentFile) {
return matchUrl.test(resolved.absolute) ? fetch(resolved.absolute).then(parseResponse) : promises.readFile(resolved.absolute, { encoding: 'utf-8' });
}

function parse(iterator, opt = {}) {
async function parse(iterator, opt = {}) {
return parse$1(iterator, Object.assign(opt, { load, resolve, cwd: opt.cwd ?? process.cwd() }));
}
function transform(css, options = {}) {
async function transform(css, options = {}) {
return transform$1(css, Object.assign(options, { load, resolve, cwd: options.cwd ?? process.cwd() }));
}

Expand Down
4 changes: 0 additions & 4 deletions dist/lib/parser/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ async function parse(iterator, opt = {}) {
let tokens = results.map(mapToken);
let i;
let loc;
// if ((<Token>tokens.at(-1))?.typ == 'EOF') {
//
// tokens.pop();
// }
for (i = 0; i < tokens.length; i++) {
if (tokens[i].typ == 'Comment') {
// @ts-ignore
Expand Down
6 changes: 3 additions & 3 deletions dist/lib/renderer/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ function renderToken(token, options = {}, reducer) {
}
}
if (val === '0') {
if (unit == 'Time') {
if (token.typ == 'Time') {
return '0s';
}
if (unit == 'Frequency') {
if (token.typ == 'Frequency') {
return '0Hz';
}
// @ts-ignore
if (unit == 'Resolution') {
if (token.typ == 'Resolution') {
return '0x';
}
return '0';
Expand Down
4 changes: 2 additions & 2 deletions dist/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { load } from './load.js';
import { resolve } from '../lib/fs/resolve.js';
export { dirname, matchUrl } from '../lib/fs/resolve.js';

function parse(iterator, opt = {}) {
async function parse(iterator, opt = {}) {
return parse$1(iterator, Object.assign(opt, { load, resolve, cwd: opt.cwd ?? process.cwd() }));
}
function transform(css, options = {}) {
async function transform(css, options = {}) {
return transform$1(css, Object.assign(options, { load, resolve, cwd: options.cwd ?? process.cwd() }));
}

Expand Down
4 changes: 2 additions & 2 deletions dist/web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { load } from './load.js';
import { resolve, dirname } from '../lib/fs/resolve.js';
export { matchUrl } from '../lib/fs/resolve.js';

function parse(iterator, opt = {}) {
async function parse(iterator, opt = {}) {
return parse$1(iterator, Object.assign(opt, {
load,
resolve,
cwd: opt.cwd ?? self.location.pathname.endsWith('/') ? self.location.pathname : dirname(self.location.pathname)
}));
}
function transform(css, options = {}) {
async function transform(css, options = {}) {
return transform$1(css, Object.assign(options, {
load,
resolve,
Expand Down
5 changes: 0 additions & 5 deletions src/lib/parser/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ export async function parse(iterator: string, opt: ParserOptions = {}): Promise<
let i: number;
let loc: Location;

// if ((<Token>tokens.at(-1))?.typ == 'EOF') {
//
// tokens.pop();
// }

for (i = 0; i < tokens.length; i++) {
if (tokens[i].typ == 'Comment') {

Expand Down
6 changes: 3 additions & 3 deletions src/lib/renderer/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,18 @@ export function renderToken(token: Token, options: RenderOptions = {}, reducer?:

if (val === '0') {

if (unit == 'Time') {
if (token.typ == 'Time') {

return '0s';
}

if (unit == 'Frequency') {
if (token.typ == 'Frequency') {

return '0Hz';
}

// @ts-ignore
if (unit == 'Resolution') {
if (token.typ == 'Resolution') {

return '0x';
}
Expand Down
4 changes: 2 additions & 2 deletions src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export * from '../lib/fs';
import {parse as doParse, transform as doTransform} from "../lib";
import {load, resolve} from "../node";

export function parse(iterator: string, opt: ParserOptions = {}): Promise<ParseResult> {
export async function parse(iterator: string, opt: ParserOptions = {}): Promise<ParseResult> {

return doParse(iterator, Object.assign(opt, {load, resolve, cwd: opt.cwd ?? process.cwd()}));
}

export function transform(css: string, options: TransformOptions = {}): Promise<TransformResult> {
export async function transform(css: string, options: TransformOptions = {}): Promise<TransformResult> {

return doTransform(css, Object.assign(options, {load, resolve, cwd: options.cwd ?? process.cwd()}));
}
4 changes: 2 additions & 2 deletions src/web/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export * from '../lib/fs';
import {parse as doParse, transform as doTransform} from "../lib";
import {dirname, load, resolve} from "./index";

export function parse(iterator: string, opt: ParserOptions = {}): Promise<ParseResult> {
export async function parse(iterator: string, opt: ParserOptions = {}): Promise<ParseResult> {

return doParse(iterator, Object.assign(opt, {
load,
Expand All @@ -16,7 +16,7 @@ export function parse(iterator: string, opt: ParserOptions = {}): Promise<ParseR
}));
}

export function transform(css: string, options: TransformOptions = {}): Promise<TransformResult> {
export async function transform(css: string, options: TransformOptions = {}): Promise<TransformResult> {

return doTransform(css, Object.assign(options, {
load,
Expand Down
24 changes: 24 additions & 0 deletions test/specs/block.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,30 @@ abbr[title], abbr[data-original-title], abbr>[data-original-title] {
background-color: var(--bs-nav-pills-link-active-bg) /*! this is a comment */
}
}
}`));
});

it('media query #20', function () {
const file = `
@media all {.site-header .logo {
transition: all 0s ease 0s; flex: 0 1 0%; position: relative; align-self: stretch; display: flex; align-items: center; }}
`;
return parse(file, {
minify: true,
nestingRules: true
}).then(result => f(render(result.ast, {
minify: false,
removeComments: true,
preserveLicense: true
}).code).equals(`.site-header .logo {
transition: all 0s ease 0s;
flex: 0 1 0%;
position: relative;
align-self: stretch;
display: flex;
align-items: center
}`));
});
});
26 changes: 26 additions & 0 deletions test/specs/block.web-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,30 @@ abbr[title], abbr[data-original-title], abbr>[data-original-title] {
}
}`));
});



it('media query #20', function () {
const file = `
@media all {.site-header .logo {
transition: all 0s ease 0s; flex: 0 1 0%; position: relative; align-self: stretch; display: flex; align-items: center; }}
`;
return parse(file, {
minify: true,
nestingRules: true
}).then(result => f(render(result.ast, {
minify: false,
removeComments: true,
preserveLicense: true
}).code).equals(`.site-header .logo {
transition: all 0s ease 0s;
flex: 0 1 0%;
position: relative;
align-self: stretch;
display: flex;
align-items: center
}`));
});
});

0 comments on commit a59a29d

Please sign in to comment.