Skip to content

Commit

Permalink
fix: Add babel
Browse files Browse the repository at this point in the history
  • Loading branch information
DimChtz committed Mar 15, 2024
1 parent ec6ccd3 commit 2692100
Show file tree
Hide file tree
Showing 12 changed files with 1,616 additions and 419 deletions.
11 changes: 11 additions & 0 deletions .babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
[
"@babel/env", {
// "targets": {
// "node": "current"
// }
}
]
]
}
8 changes: 6 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
"semi": [2, "always"],
"quotes": ["error", "single"]
},
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
"ecmaVersion": 2020,
"sourceType": "module",
"presets": [
"@babel/preset-env"
]
},
"env": {
"node": true,
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ coverage/
.npmrc
.eslintrc.json
.releaserc.json
.babelrc.json
jest.config.js
rollup.config.js
12 changes: 8 additions & 4 deletions __tests__/basic.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const postcss = require('postcss');
const plugin = require('../dist/index.cjs');
const path = require('path');
const fs = require('fs');
import postcss from 'postcss';
import plugin from '../src/index.js';
import path from 'path';
import fs from 'fs';
import { fileURLToPath } from 'url';

async function process(input, opts = {}) {
return await postcss([plugin(opts)]).process(input, {from: undefined});
Expand All @@ -15,6 +16,9 @@ async function run(input, output, opts = {}) {
}

function loadFixtures(name) {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

return [
fs.readFileSync(path.join(__dirname, `fixtures/${name}.css`)).toString(),
fs.readFileSync(path.join(__dirname, `fixtures/${name}.expected.css`)).toString()
Expand Down
2 changes: 1 addition & 1 deletion dist/index.cjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"use strict";var e={matchAlignValues:/^(_|(!?(center|start|end|between|around)))(\/(_|(!?(center|start|end|between|around))))?$/,matchWrapValues:/^!?(wrap|nowrap)$/,matchDirValues:/^!?-?(row|col)$/,matchGapValues:/^(_|(!?(\d+[a-z]+)))(\/(_|(!?(\d+[a-z]+))))?$/,valuesMapper:{start:"flex-start",end:"flex-end",center:"center",between:"space-between",around:"space-around",wrap:"wrap",nowrap:"nowrap",row:"row",col:"col","-row":"row-reverse","-col":"column-reverse"},baseStyles:["display: flex;"]};const a=(a,t,r,s=!0)=>{const[n,l]=(e=>e.startsWith("!")?[!0,e.slice(1)]:[!1,e])(a),c=n?" !important":"",o=s?e.valuesMapper[l]:l;return r.push(`${t}: ${o}${c};`),r},t=(e,t,r,s=!0)=>1==e.length?(r=a(e[0],t[0],r,s),r=a(e[0],t[1],r,s)):("_"!==e[0]&&(r=a(e[0],t[0],r,s)),"_"!==e[1]&&(r=a(e[1],t[1],r,s)),r);function r(){return{postcssPlugin:"postcss-flexup",Declaration:{flexup:r=>{r.parent.append((r=>{let s=[...e.baseStyles];return r.split(" ").forEach((r=>{"_"==r||(r.match(e.matchAlignValues)?s=t(r.split("/"),["justify-content","align-items"],s,!0):r.match(e.matchWrapValues)?s=a(r,"flex-wrap",s):r.match(e.matchDirValues)?s=a(r,"flex-direction",s):r.match(e.matchGapValues)&&(s=t(r.split("/"),["column-gap","row-gap"],s,!1)))})),"\n"+s.join("\n")})(r.toString())),r.remove()}}}}r.postcss=!0,module.exports=r;
"use strict";function t(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var n,a,o,l,c=[],i=!0,u=!1;try{if(o=(e=e.call(t)).next,0===r){if(Object(e)!==e)return;i=!1}else for(;!(i=(n=o.call(e)).done)&&(c.push(n.value),c.length!==r);i=!0);}catch(t){u=!0,a=t}finally{try{if(!i&&null!=e.return&&(l=e.return(),Object(l)!==l))return}finally{if(u)throw a}}return c}}(t,r)||e(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t){return function(t){if(Array.isArray(t))return n(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||e(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function e(t,r){if(t){if("string"==typeof t)return n(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?n(t,r):void 0}}function n(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var a={matchAlignValues:/^(_|(!?(center|start|end|between|around)))(\/(_|(!?(center|start|end|between|around))))?$/,matchWrapValues:/^!?(wrap|nowrap)$/,matchDirValues:/^!?-?(row|col)$/,matchGapValues:/^(_|(!?(\d+[a-z]+)))(\/(_|(!?(\d+[a-z]+))))?$/,valuesMapper:{start:"flex-start",end:"flex-end",center:"center",between:"space-between",around:"space-around",wrap:"wrap",nowrap:"nowrap",row:"row",col:"col","-row":"row-reverse","-col":"column-reverse"},baseStyles:["display: flex;"]},o=function(r,e,n){var o=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],l=function(t){return t.startsWith("!")?[!0,t.slice(1)]:[!1,t]}(r),c=t(l,2),i=c[0],u=c[1],s=i?" !important":"",p=o?a.valuesMapper[u]:u;return n.push("".concat(e,": ").concat(p).concat(s,";")),n},l=function(t,r,e){var n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return 1==t.length?(e=o(t[0],r[0],e,n),e=o(t[0],r[1],e,n)):("_"!==t[0]&&(e=o(t[0],r[0],e,n)),"_"!==t[1]&&(e=o(t[1],r[1],e,n)),e)};function c(){return{postcssPlugin:"postcss-flexup",Declaration:{flexup:function(t){var e,n;t.parent.append((e=t.toString(),n=r(a.baseStyles),e.split(" ").forEach((function(t){"_"==t||(t.match(a.matchAlignValues)?n=l(t.split("/"),["justify-content","align-items"],n,!0):t.match(a.matchWrapValues)?n=o(t,"flex-wrap",n):t.match(a.matchDirValues)?n=o(t,"flex-direction",n):t.match(a.matchGapValues)&&(n=l(t.split("/"),["column-gap","row-gap"],n,!1)))})),"\n"+n.join("\n"))),t.remove()}}}}c.postcss=!0,module.exports=c;
//# sourceMappingURL=index.cjs.map
2 changes: 1 addition & 1 deletion dist/index.cjs.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2692100

Please sign in to comment.