feat: allow custom decorator fields

Open
#3,144 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
typescript
Domain
tooling

Research direction

The issue names no files or tests; start by tracing decorator definitions into compiler metadata and the output target plugin process. Done means component authors can provide arbitrary custom data on decorators and output targets can access it for component-specific configuration.

Written by the indexing model from the issue text.

Description

Feature: Want this? Upvote it!
Prerequisites
Describe the Feature Request

Allow component authors to pass arbitrary data to Stencil's decorators, that can then be accessed in the compiler metadata during the output target process.

Describe the Use Case

Stencil's output target plugin system is a really unique and powerful feature of Stencil. However, configuration of output targets is only currently possible in the Stencil config file. This is fine for high level config options that affect all components, but in some circumstances it might be useful to allow for configuration in individual component files.

Example:

Consider an output target that outputs GrapesJS drag-and-drop editor plugins. I might want a field on Props, grapesExclude, that dictates whether the prop is exposed in the GrapesJS GUI.

Prop({
  custom: {
    grapesExclude: true
  }
}) foo;

Example2:

Perhaps I want to alter the name of a specific component, but only when it is output to React?

Component({
  custom: {
    reactName: 'MyReactComponent'
  }
});
Describe Preferred Solution

My current thinking is an additional field in all decorators:

custom: any

Describe Alternatives

No response

Related Code

No response

Additional Information

I think this kind of flexibility could open up some neat functionality in the output targets. If anyone else has any additional potential use cases, please post below!

Dominant language
TypeScript
Stars
13.1k
Forks
855
Avg merge
4h 7m
Merged PRs (30d)
44

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stenciljs/core

All issues in stenciljs/core

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.