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: add .root() to avoid re-parsing inputs when possible #717

Merged
merged 2 commits into from
Feb 5, 2020

Conversation

jquense
Copy link
Contributor

@jquense jquense commented Feb 5, 2020

Description

Accept a postcss Root object as an input. Allows for minor optimization in a tool chain, where the input may also be using postcss...such as webpack loader chain, where the previous loader may return it's AST as well as the resulting string.

Motivation and Context

nitty-gritty optimization territory. Cases where it doesn't make sense, or not preferable to pass plugins directly to processor.before.

How Has This Been Tested?

I added a test!

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov
Copy link

codecov bot commented Feb 5, 2020

Codecov Report

Merging #717 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #717      +/-   ##
==========================================
+ Coverage   98.44%   98.46%   +0.02%     
==========================================
  Files          45       45              
  Lines        1157     1173      +16     
  Branches      179      182       +3     
==========================================
+ Hits         1139     1155      +16     
  Misses         15       15              
  Partials        3        3
Impacted Files Coverage Δ
packages/processor/processor.js 100% <100%> (ø) ⬆️
packages/svelte/svelte.js 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9b14f12...c0c5678. Read the comment docs.

Copy link
Owner

@tivac tivac left a comment

Choose a reason for hiding this comment

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

Delete yarn.lock please, package-lock.json is the canonical lockfile for this repo.

@@ -351,7 +362,7 @@ class Processor {

// Take a file id and some text, walk it for dependencies, then
// process and return details
async _add(id, text) {
async _add(id, textOrRoot) {
Copy link
Owner

Choose a reason for hiding this comment

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

textOrRoot -> src

@@ -424,7 +435,7 @@ class Processor {

// Process files and walk their composition/value dependency tree to find
// new files we need to process
async _walk(name, text) {
async _walk(name, textOrRoot) {
Copy link
Owner

Choose a reason for hiding this comment

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

textOrRoot -> src

@@ -433,6 +444,10 @@ class Processor {
return;
}

const text = typeof textOrRoot === "string" ?
Copy link
Owner

Choose a reason for hiding this comment

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

Do this inside the assignment to this._files[name] since nothing else depends on it.

@tivac
Copy link
Owner

tivac commented Feb 5, 2020

@jquense this is great and I'm kinda gobsmacked I didn't already add this 😳 Thanks!

Copy link
Owner

@tivac tivac left a comment

Choose a reason for hiding this comment

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

👍🏻🚀

@tivac tivac changed the title feat: add root() to avoid re-parsing inputs when possible feat: add .root() to avoid re-parsing inputs when possible Feb 5, 2020
@tivac tivac merged commit fdb010b into tivac:master Feb 5, 2020
@jquense jquense deleted the processor-ast branch February 5, 2020 18:10
@jquense
Copy link
Contributor Author

jquense commented Feb 5, 2020

thanks!

@tivac
Copy link
Owner

tivac commented Feb 5, 2020

This is released in @modular-css/processor@25.4.0, and also documented on m-css.com

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.

2 participants