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

Add Source Maps 🗺 #320

Merged
merged 40 commits into from
Sep 24, 2017
Merged

Add Source Maps 🗺 #320

merged 40 commits into from
Sep 24, 2017

Conversation

tkh44
Copy link
Member

@tkh44 tkh44 commented Sep 21, 2017

What:
Add sourcemaps like styled-jsx has.

Only one sourcemap is allowed per style tag so we make each insert use a new tag. The rough plan is to insert the sourcemap for the user with the babel plugin in dev mode. I am not sure how to do this process for dev and the current process for production. I've never seen a babel plugin that checks NODE_ENV. Is this a thing?

Checklist:

  • Documentation
  • Tests
  • Code complete

closes #15

@tkh44
Copy link
Member Author

tkh44 commented Sep 22, 2017

I still need to document this, but I do want to get it into the next release.

@tkh44
Copy link
Member Author

tkh44 commented Sep 22, 2017

This doesn't work with object styles. I'm not sure how to handle them yet. I don't think this should block the merge though.

@codecov
Copy link

codecov bot commented Sep 22, 2017

Codecov Report

Merging #320 into master will increase coverage by 0.76%.
The diff coverage is 97.59%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #320      +/-   ##
=========================================
+ Coverage   96.53%   97.3%   +0.76%     
=========================================
  Files          16      17       +1     
  Lines         577     593      +16     
  Branches      138     142       +4     
=========================================
+ Hits          557     577      +20     
+ Misses         15      12       -3     
+ Partials        5       4       -1
Impacted Files Coverage Δ
packages/babel-plugin-emotion/src/source-map.js 100% <100%> (ø)
packages/babel-plugin-emotion/src/ast-object.js 100% <100%> (ø) ⬆️
packages/babel-plugin-emotion/src/macro.js 100% <100%> (ø) ⬆️
packages/emotion/src/index.js 100% <100%> (ø) ⬆️
packages/emotion-server/src/index.js 100% <100%> (ø) ⬆️
packages/babel-plugin-emotion/src/macro-styled.js 100% <100%> (ø) ⬆️
packages/emotion/src/sheet.js 84.44% <92.3%> (+11.71%) ⬆️
packages/babel-plugin-emotion/src/index.js 94.77% <93.75%> (-0.58%) ⬇️

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 baf9b95...f70efe2. Read the comment docs.

package.json Outdated
"dependencies": {
"convert-source-map": "^1.5.0",
"source-map": "^0.5.7"
},
Copy link
Member

@emmatown emmatown Sep 22, 2017

Choose a reason for hiding this comment

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

Should these be in babel-plugin-emotion's package.json?

currentSourceMap = ''
}
}

Copy link
Member

@emmatown emmatown Sep 22, 2017

Choose a reason for hiding this comment

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

Maybe instead of putting the source map inside of the styles we could make an object the first argument to createStyles if there is a source map and do something like this.

let sourceMap = ''

function createStyles(strings, ...interpolations) {
  if (process.env.NODE_ENV !== 'production') {
    if (strings !== undefined && strings.sourceMap !== undefined) {
      sourceMap = strings
      return createStyles(...interpolations)
    }
  }
  let stringMode = true
  let styles = ''
  if (
    (strings !== undefined && strings.raw === undefined) ||
    strings === undefined
  ) {
    stringMode = false
    styles = handleInterpolation(strings, false)
  } else {
    styles = strings[0]
  }
  interpolations.forEach((interpolation, i) => {
    styles += handleInterpolation(interpolation, isLastCharDot(styles))
    if (stringMode === true && strings[i + 1] !== undefined) {
      styles += strings[i + 1]
    }
  })
  return styles
}

Copy link
Member Author

Choose a reason for hiding this comment

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

This is close to what I did.

@tkh44 tkh44 closed this Sep 24, 2017
@tkh44 tkh44 reopened this Sep 24, 2017
@tkh44
Copy link
Member Author

tkh44 commented Sep 24, 2017

source-map-demo

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.

sourcemaps?
2 participants