Coder Social home page Coder Social logo

Babel preset about dom-chef HOT 7 CLOSED

vadimdemedes avatar vadimdemedes commented on September 26, 2024
Babel preset

from dom-chef.

Comments (7)

fregante avatar fregante commented on September 26, 2024 3

If someone actually makes a babel plugin out of dom-chef I'd love to actually see JSX converted into plain DOM calls like Svelte does. That stuff is amazing:

<h1>Hello {{name}}!</h1>
// ...
create: function () {
	h1 = createElement( 'h1' );
	text = createText( "Hello " );
	text_1 = createText( text_1_value = state.name );
	text_2 = createText( "!" );
},

mount: function ( target, anchor ) {
	insertNode( h1, target, anchor );
	appendNode( text, h1 );
	appendNode( text_1, h1 );
	appendNode( text_2, h1 );
},
// ...

Svelte unfortunately adds a little unnecessary boilerplate to keep it dynamic and app-like, otherwise I'd have used that in Refined GitHub instead.

from dom-chef.

fregante avatar fregante commented on September 26, 2024 3

Apparently babel 7.9.0 automatically imports React:

https://babeljs.io/blog/2020/03/16/7.9.0#a-new-jsx-transform-11154-https-githubcom-babel-babel-pull-11154

Due to:

https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md#auto-import

I think our config would be:

    [
      "@babel/preset-react",
      {
        "pragma": "h",
        "pragmaFrag": "DocumentFragment",
        "runtime": "automatic", // enables auto-import
        "importSource": "dom-chef"
      }
    ]
  ]

From: https://babeljs.io/docs/en/babel-preset-react#with-a-configuration-file-recommended

So now this is a documentation-only issue, which would follow #56 and then #57

from dom-chef.

fregante avatar fregante commented on September 26, 2024

Bingo: https://github.com/treycordova/nativejsx and https://github.com/treycordova/nativejsx-loader

export const check = <svg aria-hidden="true" class="octicon octicon-check" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z"></path></svg>;
export const check = function () {
    const _a = document.createElement('svg');
    _a.setAttribute('aria-hidden', 'true');
    _a.setAttribute('class', 'octicon octicon-check');
    _a.setAttribute('height', '16');
    _a.setAttribute('version', '1.1');
    _a.setAttribute('viewBox', '0 0 12 16');
    _a.setAttribute('width', '12');
    const _b = document.createElement('path');
    _b.setAttribute('d', 'M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z');
    _a.appendChild(_b);
    return _a;
}.call(this);

Two issues:

from dom-chef.

vadimdemedes avatar vadimdemedes commented on September 26, 2024

@sindresorhus Great idea! Agree with every point.

@bfred-it That stuff is great, I'll keep that in mind.

from dom-chef.

dankotov avatar dankotov commented on September 26, 2024

Apologies for a perhaps noob question, however, according to babel docs, pragma and pragmaFrag cannot be set with runtime: "automatic". Is dom-chef therefore not compatible with automatic runtime?

docs: https://babeljs.io/docs/en/babel-preset-react#with-a-configuration-file-recommended

from dom-chef.

fregante avatar fregante commented on September 26, 2024

@dankotov correct. That's #57

from dom-chef.

dankotov avatar dankotov commented on September 26, 2024

@fregante understood! appreciate the prompt reply

from dom-chef.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.