Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
chore: Initial preview release
Browse files Browse the repository at this point in the history
  • Loading branch information
mohebifar committed Feb 25, 2024
1 parent cd7945a commit 38b2663
Show file tree
Hide file tree
Showing 35 changed files with 995 additions and 47 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
13 changes: 13 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"mode": "pre",
"tag": "dev",
"initialVersions": {
"docs": "1.0.0",
"@react-unforget/compiler": "0.0.0",
"@react-unforget/eslint-config": "0.0.0",
"@react-unforget/jest-config": "0.0.0",
"@react-unforget/runtime": "0.0.0",
"@react-unforget/typescript-config": "0.0.0"
},
"changesets": []
}
7 changes: 7 additions & 0 deletions .changeset/wild-dryers-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@react-unforget/eslint-config": patch
"@react-unforget/compiler": patch
"@react-unforget/runtime": patch
---

Initial dev release
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
push:
branches: ["main"]
pull_request:
types: [opened, synchronize]

jobs:
build:
name: Build and Test
timeout-minutes: 15
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: "yarn"

- name: Install dependencies
run: yarn

- name: Build
run: yarn build

- name: Test
run: yarn test

- name: Lint
run: yarn lint
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: Install Dependencies
run: yarn

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Mohamad Mohebifar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"build": "turbo build",
"dev": "turbo dev",
"lint": "turbo lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\""
"test": "turbo test",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"publish": "changeset publish"
},
"devDependencies": {
"@react-unforget/eslint-config": "*",
Expand All @@ -20,5 +22,8 @@
"workspaces": [
"apps/*",
"packages/*"
]
],
"dependencies": {
"@changesets/cli": "^2.27.1"
}
}
2 changes: 1 addition & 1 deletion .eslintrc.js → packages/compiler/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// This configuration only applies to the package manager root.
/** @type {import("eslint").Linter.Config} */
module.exports = {
ignorePatterns: ["apps/**", "packages/**"],
extends: ["@react-unforget/eslint-config/library.js"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
tsConfigRootDir: __dirname,
},
};
18 changes: 16 additions & 2 deletions packages/compiler/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
{
"name": "@react-unforget/compiler",
"version": "0.0.0",
"private": true,
"license": "MIT",
"type": "module",
"files": [
"dist",
"README.md"
],
"main": "dist/main.js",
"module": "dist/main.mjs",
"types": "dist/main.d.ts",
"exports": {
".": {
"import": "./dist/main.mjs",
"require": "./dist/main.js",
"types": "./dist/main.d.ts"
}
},
"scripts": {
"dev": "yarn build --watch",
"build": "tsup src/main.ts --dts --format cjs,esm",
"test": "jest",
"lint": "eslint . --max-warnings 0"
"lint": "eslint src/**/* --max-warnings 10"
},
"devDependencies": {
"@babel/plugin-syntax-jsx": "^7.23.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import * as t from "@babel/types";
import { RUNTIME_MODULE_CACHE_ENQUEUE_METHOD_NAME } from "~/utils/constants";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import * as t from "@babel/types";
import { ComponentVariable } from "~/classes/ComponentVariable";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import * as t from "@babel/types";
import { unwrapPatternAssignment } from "~/utils/unwrap-pattern-assignment";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import * as t from "@babel/types";

export function variableDeclarationToAssignment(
Expand Down
1 change: 1 addition & 0 deletions packages/compiler/src/classes/Component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import { Binding } from "@babel/traverse";
import * as t from "@babel/types";
import {
Expand Down
7 changes: 6 additions & 1 deletion packages/compiler/src/classes/ComponentVariable.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import { Binding } from "@babel/traverse";
import * as t from "@babel/types";
import { makeCacheEnqueueCallStatement } from "~/ast-factories/make-cache-enqueue-call-statement";
Expand Down Expand Up @@ -188,7 +189,11 @@ export class ComponentVariable {
const binding = this.component.path.scope.getBinding(id);

if (binding) {
dependent = this.component.addComponentVariable(binding);
const newComponentVariable =
this.component.addComponentVariable(binding);
if (newComponentVariable) {
dependent = newComponentVariable;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/compiler/src/classes/tests/Component.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import { Component } from "~/classes/Component";
import { parse } from "~/utils/testing";

Expand Down
1 change: 1 addition & 0 deletions packages/compiler/src/find-component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import traverse from "@babel/traverse";
import { getReturnsOfFunction } from "./utils/get-returns-of-function";
import { Component } from "./classes/Component";
Expand Down
2 changes: 2 additions & 0 deletions packages/compiler/src/utils/errors/RightmostIdNotFound.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type * as babel from "@babel/core";

export class RightmostIdNotFound extends Error {
constructor(path: babel.NodePath) {
super("Could not find rightmost identifier name for" + path.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type * as babel from "@babel/core";

export function getDeclaredIdentifiersInLVal(
lval: babel.NodePath<babel.types.LVal | null>,
identifiers: Set<string> = new Set()
Expand Down
2 changes: 2 additions & 0 deletions packages/compiler/src/utils/get-function-parent.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type * as babel from "@babel/core";

// The native NodePath#getFunctionParent does not recognize the parent of a function if it is a variable declarator.
export function getFunctionParent(path: babel.NodePath<babel.types.Node>) {
const parent = path.findParent((p) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import type { Binding } from "@babel/traverse";

export function getReferencedVariablesInside(
Expand Down
1 change: 1 addition & 0 deletions packages/compiler/src/utils/get-returns-of-function.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import { getFunctionParent } from "./get-function-parent";

export function getReturnsOfFunction(fn: babel.NodePath<babel.types.Function>) {
Expand Down
15 changes: 7 additions & 8 deletions packages/compiler/src/utils/get-rightmost-id-name.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import type * as babel from "@babel/core";
import { RightmostIdNotFound } from "./errors/RightmostIdNotFound";

export function getRightmostIdName(
path: babel.NodePath<
babel.types.Expression | babel.types.V8IntrinsicIdentifier
>
): string {
let currentPath = path;

if (currentPath.isMemberExpression()) {
const property = currentPath.get("property");
if (path.isMemberExpression()) {
const property = path.get("property");

if (property.isStringLiteral()) {
return property.node.value;
} else if (property.isIdentifier() && !currentPath.node.computed) {
} else if (property.isIdentifier() && !path.node.computed) {
return property.node.name;
} else if (property.isNumericLiteral()) {
return property.node.value.toString();
}
} else if (currentPath.isIdentifier()) {
return currentPath.node.name;
} else if (path.isIdentifier()) {
return path.node.name;
}

throw new RightmostIdNotFound(currentPath);
throw new RightmostIdNotFound(path);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import { Component } from "../classes/Component";
import { ComponentVariable } from "../classes/ComponentVariable";
import { getReferencedVariablesInside } from "./get-referenced-variables-inside";
Expand Down
1 change: 1 addition & 0 deletions packages/compiler/src/utils/is-hook-call.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import { getRightmostIdName } from "./get-rightmost-id-name";

export function isHookCall(path: babel.NodePath<babel.types.CallExpression>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import { getDeclaredIdentifiersInLVal } from "../get-declared-identifiers-in-lval";
import { parse } from "../testing";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import { getReferencedVariablesInside } from "../get-referenced-variables-inside";
import { parse } from "../testing";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import { RightmostIdNotFound } from "../errors/RightmostIdNotFound";
import { getRightmostIdName } from "../get-rightmost-id-name";
import { parse } from "../testing";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import * as t from "@babel/types";
import { generate, parse } from "../testing";
import { unwrapPatternAssignment } from "../unwrap-pattern-assignment";
Expand Down
36 changes: 22 additions & 14 deletions packages/compiler/src/utils/unwrap-pattern-assignment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as babel from "@babel/core";
import * as t from "@babel/types";
import { DEFAULT_UNUSED_VARIABLE_NAME } from "./constants";

Expand Down Expand Up @@ -32,9 +33,13 @@ export function unwrapPatternAssignment(
return [
{
id: t.arrayPattern(
Array.from({ length: index }, (_, i) =>
lval.scope.generateUidIdentifier(DEFAULT_UNUSED_VARIABLE_NAME)
).concat([element.node as babel.types.RestElement] as any[])
Array.from(
{ length: index },
() =>
lval.scope.generateUidIdentifier(
DEFAULT_UNUSED_VARIABLE_NAME
) as babel.types.Identifier | babel.types.RestElement
).concat([element.node as babel.types.RestElement])
),
value: t.cloneNode(rval),
name: arg.node.name,
Expand Down Expand Up @@ -85,18 +90,21 @@ export function unwrapPatternAssignment(
id: t.objectPattern(
properties
.slice(0, index)
.map((prop) => {
const objectProp = prop.node as babel.types.ObjectProperty;
.map<babel.types.ObjectProperty | babel.types.RestElement>(
(prop) => {
const objectProp =
prop.node as babel.types.ObjectProperty;

return t.objectProperty(
t.cloneNode(objectProp).key,
t.identifier(
prop.scope.generateUid(DEFAULT_UNUSED_VARIABLE_NAME)
),
objectProp.computed
);
})
.concat([property.node as babel.types.RestElement] as any[])
return t.objectProperty(
t.cloneNode(objectProp).key,
t.identifier(
prop.scope.generateUid(DEFAULT_UNUSED_VARIABLE_NAME)
),
objectProp.computed
);
}
)
.concat([property.node as babel.types.RestElement])
),
value: t.cloneNode(rval),
name: arg.node.name,
Expand Down
Loading

0 comments on commit 38b2663

Please sign in to comment.