-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
postcss-bundler : do not shift up
@import
statements (#1161)
- Loading branch information
1 parent
2bd92ea
commit d17488a
Showing
157 changed files
with
1,070 additions
and
567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
plugin-packs/postcss-bundler/dist/postcss-import/lib/apply-conditions.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import type { AtRule, AtRuleProps } from 'postcss'; | ||
import { Statement } from './statement'; | ||
export declare function applyConditions(bundle: Array<Statement>, atRule: (defaults?: AtRuleProps) => AtRule): void; | ||
import { Stylesheet } from './statement'; | ||
export declare function applyConditions(stylesheet: Stylesheet, atRule: (defaults?: AtRuleProps) => AtRule): void; |
4 changes: 2 additions & 2 deletions
4
plugin-packs/postcss-bundler/dist/postcss-import/lib/apply-styles.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import type { Document, Root } from 'postcss'; | ||
import { Statement } from './statement'; | ||
export declare function applyStyles(bundle: Array<Statement>, styles: Root | Document): void; | ||
import { Stylesheet } from './statement'; | ||
export declare function applyStyles(stylesheet: Stylesheet, styles: Root | Document): void; |
2 changes: 2 additions & 0 deletions
2
plugin-packs/postcss-bundler/dist/postcss-import/lib/base64-encoded-import.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { Condition } from './conditions'; | ||
export declare function base64EncodedConditionalImport(prelude: string, conditions: Array<Condition>): string; |
4 changes: 2 additions & 2 deletions
4
plugin-packs/postcss-bundler/dist/postcss-import/lib/parse-styles.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import type { Document, Postcss, Result, Root, AtRule } from 'postcss'; | ||
import { Statement } from './statement'; | ||
import { Stylesheet } from './statement'; | ||
import { Condition } from './conditions'; | ||
export declare function parseStyles(result: Result, styles: Root | Document, importingNode: AtRule | null, conditions: Array<Condition>, from: Array<string>, postcss: Postcss): Promise<Statement[]>; | ||
export declare function parseStyles(result: Result, styles: Root | Document, importingNode: AtRule | null, conditions: Array<Condition>, from: Array<string>, postcss: Postcss): Promise<Stylesheet>; |
4 changes: 2 additions & 2 deletions
4
.../postcss-import/lib/parse-statements.d.ts → .../postcss-import/lib/parse-stylesheet.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import type { AtRule, Document, Result, Root } from 'postcss'; | ||
import { Condition } from './conditions'; | ||
import { Statement } from './statement'; | ||
export declare function parseStatements(result: Result, styles: Root | Document, importingNode: AtRule | null, conditions: Array<Condition>, from: Array<string>): Array<Statement>; | ||
import { Stylesheet } from './statement'; | ||
export declare function parseStylesheet(result: Result, styles: Root | Document, importingNode: AtRule | null, conditions: Array<Condition>, from: Array<string>): Stylesheet; |
3 changes: 3 additions & 0 deletions
3
plugin-packs/postcss-bundler/dist/postcss-import/lib/post-process.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type { AtRule, AtRuleProps } from 'postcss'; | ||
import { Stylesheet } from './statement'; | ||
export declare function postProcess(stylesheet: Stylesheet, atRule: (defaults?: AtRuleProps) => AtRule): void; |
26 changes: 15 additions & 11 deletions
26
plugin-packs/postcss-bundler/dist/postcss-import/lib/statement.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,38 @@ | ||
import type { AtRule, ChildNode, Warning } from 'postcss'; | ||
import { Condition } from './conditions'; | ||
export type Statement = ImportStatement | CharsetStatement | NodesStatement | Warning; | ||
export type Stylesheet = { | ||
charset?: AtRule; | ||
statements: Array<Statement>; | ||
}; | ||
export type Statement = ImportStatement | PreImportStatement | NodesStatement | Warning; | ||
export type NodesStatement = { | ||
type: string; | ||
type: 'nodes'; | ||
nodes: Array<ChildNode>; | ||
conditions: Array<Condition>; | ||
from: Array<string>; | ||
parent?: Statement; | ||
importingNode: AtRule | null; | ||
}; | ||
export type CharsetStatement = { | ||
type: string; | ||
export type ImportStatement = { | ||
type: 'import'; | ||
uri: string; | ||
fullUri: string; | ||
node: AtRule; | ||
conditions: Array<Condition>; | ||
from: Array<string>; | ||
parent?: Statement; | ||
stylesheet?: Stylesheet; | ||
importingNode: AtRule | null; | ||
}; | ||
export type ImportStatement = { | ||
type: string; | ||
uri: string; | ||
fullUri: string; | ||
node: AtRule; | ||
export type PreImportStatement = { | ||
type: 'pre-import'; | ||
node: ChildNode; | ||
conditions: Array<Condition>; | ||
from: Array<string>; | ||
parent?: Statement; | ||
children?: Array<Statement>; | ||
importingNode: AtRule | null; | ||
}; | ||
export declare function isWarning(stmt: Statement): stmt is Warning; | ||
export declare function isNodesStatement(stmt: Statement): stmt is NodesStatement; | ||
export declare function isCharsetStatement(stmt: Statement): stmt is CharsetStatement; | ||
export declare function isImportStatement(stmt: Statement): stmt is ImportStatement; | ||
export declare function isPreImportStatement(stmt: Statement): stmt is PreImportStatement; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 11 additions & 6 deletions
17
plugin-packs/postcss-bundler/src/postcss-import/lib/apply-styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
plugin-packs/postcss-bundler/src/postcss-import/lib/base64-encoded-import.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Condition } from './conditions'; | ||
import { formatImportPrelude } from './format-import-prelude'; | ||
|
||
// Base64 encode an import with conditions | ||
// The order of conditions is important and is interleaved with cascade layer declarations | ||
// Each group of conditions and cascade layers needs to be interpreted in order | ||
// To achieve this we create a list of base64 encoded imports, where each import contains a stylesheet with another import. | ||
// Each import can define a single group of conditions and a single cascade layer. | ||
export function base64EncodedConditionalImport(prelude: string, conditions: Array<Condition>): string { | ||
conditions.reverse(); | ||
const first = conditions.pop()!; | ||
let params = `${prelude} ${formatImportPrelude( | ||
first.layer, | ||
first.media, | ||
first.supports, | ||
)}`; | ||
|
||
for (const condition of conditions) { | ||
params = `'data:text/css;base64,${Buffer.from( | ||
`@import ${params}`, | ||
).toString('base64')}' ${formatImportPrelude( | ||
condition.layer, | ||
condition.media, | ||
condition.supports, | ||
)}`; | ||
} | ||
|
||
return params; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.