Skip to content

Commit

Permalink
Replace all non-breaking spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoroth committed Feb 13, 2024
1 parent 0e4a911 commit 0a0396c
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion scripts/setupFixtures.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path"
import { glob } from "glob"
import { glob } from "glob"
import { execSync } from "child_process"

const fixtures = await glob("test/fixtures/**/package.json", { ignore: "**/**/node_modules/**" })
Expand Down
4 changes: 2 additions & 2 deletions src/class_declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ClassDeclaration {
public exportDeclaration?: ExportDeclaration;
public controllerDefinition?: ControllerDefinition

constructor(className: string | undefined, superClass: ClassDeclaration | undefined, sourceFile: SourceFile, node?: ClassDeclarationNode | undefined) {
constructor(className: string | undefined, superClass: ClassDeclaration | undefined, sourceFile: SourceFile, node?: ClassDeclarationNode | undefined) {
this.className = className
this.superClass = superClass
this.sourceFile = sourceFile
Expand Down Expand Up @@ -70,7 +70,7 @@ export class ClassDeclaration {

const tsNode = (node as unknown as TSESTree.MethodDefinition)
const methodName = ast.extractIdentifier(node.key) as string
const isPrivate = node.key.type === "PrivateIdentifier" || tsNode.accessibility === "private"
const isPrivate = node.key.type === "PrivateIdentifier" || tsNode.accessibility === "private"
const name = isPrivate ? `#${methodName}` : methodName

this.controllerDefinition.methods.push(new MethodDefinition(name, node.loc, "static"))
Expand Down
4 changes: 2 additions & 2 deletions src/controller_definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Project } from "./project"
import { ClassDeclaration } from "./class_declaration"
import { ParseError } from "./parse_error"

import { dasherize, uncapitalize } from "./util/string"
import { dasherize, uncapitalize } from "./util/string"

import { MethodDefinition, ValueDefinition, ClassDefinition, TargetDefinition } from "./controller_property_definition"

Expand Down Expand Up @@ -65,7 +65,7 @@ export class ControllerDefinition {
const hasMoreThanOneController = this.classDeclaration?.sourceFile.classDeclarations.filter(klass => klass.isStimulusDescendant).length > 1
const isProjectFile = this.classDeclaration?.sourceFile.path.includes("node_modules")

if (className && ((isProjectFile && hasMoreThanOneController) || (!isProjectFile))) {
if (className && ((isProjectFile && hasMoreThanOneController) || (!isProjectFile))) {
return dasherize(uncapitalize(className.replace("Controller", "")))
}

Expand Down
4 changes: 2 additions & 2 deletions src/packages/tailwindcss-stimulus-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { glob } from "glob"

import type { NodeModule } from "../types"
import { Project } from "../project"
import { hasDepedency, findPackagePath } from "../util/npm"
import { hasDepedency, findPackagePath } from "../util/npm"

export async function analyze(project: Project) {
const packageName = "tailwindcss-stimulus-components"
const hasPackage = await hasDepedency(project.projectPath, packageName)
const packagePath = await findPackagePath(project.projectPath, packageName)

if (!hasPackage || !packagePath) return
if (!hasPackage || !packagePath) return

const basePath = path.join(packagePath, "src")
const files = await glob(`${basePath}/**/*.js`)
Expand Down
6 changes: 3 additions & 3 deletions src/source_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class SourceFile {

this.exportDeclarations.push({
exportedName: undefined,
localName: name || nameFromId || nameFromAssignment,
localName: name || nameFromId || nameFromAssignment,
type: "default",
node
})
Expand All @@ -185,7 +185,7 @@ export class SourceFile {
const className = ast.extractIdentifier(node.id)
const superClassName = ast.extractIdentifier(node.superClass)
const importDeclaration = this.importDeclarations.find(i => i.localName === superClassName)
let superClass = this.classDeclarations.find(i => i.className === superClassName)
let superClass = this.classDeclarations.find(i => i.className === superClassName)

if (!superClass && superClassName) {
superClass = new ClassDeclaration(superClassName, undefined, this)
Expand Down Expand Up @@ -216,7 +216,7 @@ export class SourceFile {

const classDeclaration = this.classDeclarations.find(c => c.className === object.name)

if (!classDeclaration || !classDeclaration.isStimulusDescendant) return
if (!classDeclaration || !classDeclaration.isStimulusDescendant) return

properties.parseStaticControllerProperties(classDeclaration.controllerDefinition, property, expression.right)
},
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type NestedObject<T> = {
[k: string]: T | NestedObject<T>
}

export type ValueDefinitionValue = string | number | bigint | boolean | object | null | undefined
export type ValueDefinitionValue = string | number | bigint | boolean | object | null | undefined

export type ValueDefinition = {
type: string
Expand Down
14 changes: 7 additions & 7 deletions src/util/ast.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ValueDefinition } from "../controller_property_definition"
import { ValueDefinition } from "../controller_property_definition"

import type * as Acorn from "acorn"
import type { NestedObject, ValueDefinitionValue, ValueDefinition as ValueDefinitionType } from "../types"

export function findPropertyInProperties(_properties: (Acorn.Property | Acorn.SpreadElement)[], propertyName: string): Acorn.Property | undefined {
export function findPropertyInProperties(_properties: (Acorn.Property | Acorn.SpreadElement)[], propertyName: string): Acorn.Property | undefined {
const properties = _properties.filter(property => property.type === "Property") as Acorn.Property[]

return properties.find(property =>
Expand Down Expand Up @@ -57,7 +57,7 @@ export function convertObjectExpressionToValueDefinitions(objectExpression: Acor
return definitions
}

export function convertObjectExpressionToValueDefinition(objectExpression: Acorn.ObjectExpression): ValueDefinitionType | undefined {
export function convertObjectExpressionToValueDefinition(objectExpression: Acorn.ObjectExpression): ValueDefinitionType | undefined {
const typeProperty = findPropertyInProperties(objectExpression.properties, "type")
const defaultProperty = findPropertyInProperties(objectExpression.properties, "default")

Expand All @@ -83,7 +83,7 @@ export function convertObjectExpressionToValueDefinition(objectExpression: Acorn
}
}

export function convertPropertyToValueDefinition(property: Acorn.Property): ValueDefinitionType | undefined {
export function convertPropertyToValueDefinition(property: Acorn.Property): ValueDefinitionType | undefined {
switch (property.value.type) {
case "Identifier":
return {
Expand All @@ -95,7 +95,7 @@ export function convertPropertyToValueDefinition(property: Acorn.Property): Valu
}
}

export function getDefaultValueFromNode(node?: Acorn.Expression | null) {
export function getDefaultValueFromNode(node?: Acorn.Expression | null) {
if (!node) return

switch (node.type) {
Expand All @@ -110,14 +110,14 @@ export function getDefaultValueFromNode(node?: Acorn.Expression | null) {
}
}

export function extractIdentifier(node?: Acorn.AnyNode | null): string | undefined {
export function extractIdentifier(node?: Acorn.AnyNode | null): string | undefined {
if (!node) return undefined
if (!(node.type === "Identifier" || node.type === "PrivateIdentifier")) return undefined

return node.name
}

export function extractLiteral(node?: Acorn.Expression | null): string | number | bigint | boolean | RegExp | null | undefined {
export function extractLiteral(node?: Acorn.Expression | null): string | number | bigint | boolean | RegExp | null | undefined {
if (node?.type !== "Literal") return undefined

return node.value
Expand Down
4 changes: 2 additions & 2 deletions src/util/decorators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ValueDefinition, ClassDefinition, TargetDefinition } from "../controller_property_definition"
import { ValueDefinition, ClassDefinition, TargetDefinition } from "../controller_property_definition"
import { ControllerDefinition } from "../controller_definition"
import { ParseError } from "../parse_error"

Expand Down Expand Up @@ -26,7 +26,7 @@ export function parseDecorator(controllerDefinition: ControllerDefinition | unde
const identifierName = (decorator.expression.type === "Identifier") ? decorator.expression.name : undefined
const calleeName = (decorator.expression.type === "CallExpression" && decorator.expression.callee.type === "Identifier") ? decorator.expression.callee.name : undefined

const decoratorName = identifierName || calleeName
const decoratorName = identifierName || calleeName

switch (decoratorName) {
case "Target":
Expand Down
4 changes: 2 additions & 2 deletions src/util/properties.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ValueDefinition, ClassDefinition, TargetDefinition } from "../controller_property_definition"
import { ValueDefinition, ClassDefinition, TargetDefinition } from "../controller_property_definition"
import { ControllerDefinition } from "../controller_definition"
import { ParseError } from "../parse_error"

import type * as Acorn from "acorn"
import * as ast from "./ast"

export function parseStaticControllerProperties(controllerDefinition: ControllerDefinition | undefined, left: Acorn.Identifier, right: Acorn.Expression): void {
export function parseStaticControllerProperties(controllerDefinition: ControllerDefinition | undefined, left: Acorn.Identifier, right: Acorn.Expression): void {
if (!controllerDefinition) return

if (right.type === "ArrayExpression") {
Expand Down
6 changes: 3 additions & 3 deletions test/parser/javascript.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, test, describe } from "vitest"

import { parseController } from "../helpers/parse"
import { parseController } from "../helpers/parse"

import { Project } from "../../src/project"
import { SourceFile } from "../../src/source_file"
import { SourceFile } from "../../src/source_file"

describe("with JS Syntax", () => {
test("doesn't parse non Stimulus class", () => {
Expand Down Expand Up @@ -185,7 +185,7 @@ describe("with JS Syntax", () => {

test("parse methods", () => {
const code = `
import { Controller } from "@hotwired/stimulus"
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
load() {}
Expand Down
2 changes: 1 addition & 1 deletion test/parser/minified.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test, describe } from "vitest"
import { parseController } from "../helpers/parse"
import { parseController } from "../helpers/parse"

describe("compiled JavaScript", () => {
test("transpiled", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/parser/parent.inheritance.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test, describe } from "vitest"
// import { parseController } from "../helpers/parse"
// import { parseController } from "../helpers/parse"

describe("inheritance", () => {
test.skip("inherits methods", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/parser/typescript.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test, describe } from "vitest"
import { parseController } from "../helpers/parse"
import { parseController } from "../helpers/parse"

import { Project } from "../../src/project"
import { SourceFile } from "../../src/source_file"
Expand Down
2 changes: 1 addition & 1 deletion test/source_file/refresh.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from "vitest"
import { Project, SourceFile } from "../../src"
import { mockFile } from "../helpers/mock"
import { mockFile } from "../helpers/mock"

const project = new Project(process.cwd())

Expand Down

0 comments on commit 0a0396c

Please sign in to comment.