60 Commits
Author SHA1 Message Date
Ian KerinsandGitHub 633451b0da Fix mismatched JSDoc comments on Position (#2114)
Also, clarify that `column` is 1-based, like `line`.
2026-07-21 10:52:01 +02:00
Andrey Sitnik 85bf516d71 Move to oxfmt 2026-04-07 16:07:54 +00:00
Andrey Sitnik f45d36cfdb Update dependencies 2025-10-18 14:12:14 +00:00
Andrey Sitnik b8a22156cb Update dependencies 2025-05-29 13:54:36 +09:00
mizdraandGitHub ad3b622e89 Clarify documentation for node.source.end.offset (#2032)
* Clarify documentation for `node.source.end.offset`

* Add test cases for `node.source`

* Show example code for `end.offset`
2025-04-12 14:22:12 +02:00
b38a1162f1 Fix missing offset in Node#positionInside, Node#positionBy and Node#rangeBy (#2033)
* Fix `opts` argument cannot be omitted

* Assign default values to `opts` just in case

- The `opts` argument to `Node#error` is currently omissible, but we'll assign a default value just in case.

* Add test cases

* Add test cases for `Node#rangeBy({start, end})`

* Add test cases for offset

* Fix missing offset in `Node#positionInside`, `Node#positionBy` and `Node#rangeBy`

* Fix conflict resolution mistakes

---------

Co-authored-by: Andrey Sitnik <[email protected]>
2025-03-22 18:07:03 +01:00
Andrey Sitnik d3d4d735df Update ESLint config 2025-02-19 13:43:47 +00:00
Andrey Sitnik 19afb318d6 Sort source code and fix ESLint 2024-08-31 23:26:27 +02:00
Natalie Weizenbaum ff3a71c551 Use ReadonlyArray for argument types that aren't modified
This makes it possible for callers to pass in their own
`ReadonlyArray`s, and implicitly documents that these arguments aren't
modified.
2024-08-19 17:38:40 -07:00
Natalie Weizenbaum 10ac71fb4c Add a protected markDirty() method on Node
This is useful to call from subtypes.
2024-08-08 22:39:16 -07:00
Natalie Weizenbaum 8611913a4f Declare Container.normalize() as a protected method
This allows subclasses to call and override this method. This PR also
adds a shared type declaration for the common argument type used to
add or create new nodes, which eventually gets passed into
`normalize`.
2024-08-08 14:15:39 -07:00
Natalie Weizenbaum 14536bf865 Use explicit this return types for clone methods 2024-07-26 17:17:17 -07:00
Natalie Weizenbaum 07a0350b23 Universally allow Root nodes in methods that add children
Roots are always handled by `Container.normalize()`, which flattens
them out into their constituent children.
2024-07-26 16:33:59 -07:00
Andrey Sitnik c7fb782e1e Allow to pass undefined to adding methods to simplify type check 2024-02-06 22:00:37 +01:00
Andrey Sitnik 45a1a9e8d4 Better clone types 2023-07-13 21:20:43 +02:00
Andrey Sitnik 0e3c3eb115 Simplify docs 2023-07-13 20:06:40 +02:00
Andrey Sitnik cdc6dc7ee6 Revert Node#clone() type 2023-07-13 20:03:18 +02:00
Andrey Sitnik 89b7f7ac78 Update dependencies and code style 2023-07-06 13:38:48 +02:00
Andrey Sitnik 19a7e2d886 Clean up docs 2023-07-06 13:32:50 +02:00
vikaskaliramna07 3d9d33d469 fixed conflicts with API docs 2023-07-02 09:09:58 +05:30
vikaskaliramna07 95fb58f5d7 Update node.d.ts 2023-07-02 09:03:43 +05:30
vikaskaliramna07 02c2fb0d76 Update node.d.ts 2023-07-02 08:58:25 +05:30
vikaskaliramna07 534b61f24a fixed comments 2023-07-02 08:56:07 +05:30
vikaskaliramna07andGitHub f77d50195d Merge branch 'postcss:main' into main 2023-07-02 10:05:29 +00:00
vikaskaliramna07 9b3126f306 Update node.d.ts 2023-07-02 08:33:07 +05:30
Andrey Sitnik 7efb1ef604 A small fixes 2023-06-29 12:57:49 +02:00
vikaskaliramna07 c82915249f lib/node.d.ts - Documentation improved. 2023-06-29 10:20:18 +05:30
vikaskaliramna07andGitHub ee7966a499 Update node.d.ts 2023-06-29 00:42:20 +00:00
vikaskaliramna07andGitHub c7e60739e2 Update node.d.ts 2023-06-29 00:40:33 +00:00
c7f3bae993 Update lib/node.d.ts
Co-authored-by: Andrey Sitnik <[email protected]>
2023-06-28 19:58:16 +00:00
vikaskaliramna07andGitHub ad10f6db22 Update node.d.ts 2023-06-28 19:57:49 +00:00
vikaskaliramna07 1ee3cbf61b Update node.d.ts
Removed extra whitespace.
2023-06-28 12:25:50 +05:30
vikaskaliramna07 6627a60658 lib/node.d.ts - Improved documentation.
Improved documentation in lib/node.d.ts module.
2023-06-28 12:23:28 +05:30
Remco Haszing f739b0bde1 Use ESM imports in type definitions 2023-03-27 18:45:38 +02:00
Remco Haszing 676fb8a0ae Fix default exports with inheritance 2023-03-27 18:08:45 +02:00
Remco Haszing c5275ddc7b Add back support for default in type definitions 2023-03-02 12:35:05 +01:00
Remco Haszing cae533107d Fix type definitions
Many files from postcss are exported. Each of this file is written using
the syntax:

```js
module.exports = Thing
```

This should be typed as:

```ts
export = Thing
```

If such a file needs to export additional types, a namespace should be
used.

However, it was typed as:

```ts
export default thing
```

This was solved at the time in #1459 (by me) by adding the following
code to each module:

```js
Thing.default = Thing
```

Whilst affective at the time, this was not the correct solution. The
introduction of the `"module": "node16"` option in TypeScript made this
issue more apparent. I recommend to remove this in a next semver major
release.

Usage has changed as follows:

**cts**

```jsonc
// tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node16"
  }
}
```

```ts
// Old
import postcss = require('postcss')

postcss.default(/* … */)
```

```ts
// New
import postcss = require('postcss')

postcss(/* … */)
```

**cjs**

```jsonc
// tsconfig.json
{
  "compilerOptions": {
    "checkJs": true,
    "module": "commonjs",
    "moduleResolution": "node16"
  }
}
```

```ts
// Old
const postcss = require('postcss')

postcss.default(/* … */)
```

```ts
// New
const postcss = require('postcss')

postcss(/* … */)
```

**mts** / **mjs**

```jsonc
// tsconfig.json
{
  "compilerOptions": {
    "module": "node16"
  }
}
```

```ts
// Old
import postcss from 'postcss'

postcss.default(/* … */)
```

```ts
// New
import postcss from 'postcss'

postcss(/* … */)
```

**bundler**

```jsonc
// tsconfig.json
{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "module": "esnext",
    "moduleResolution": "node16"
  }
}
```

```ts
// Unchanged
import postcss from 'postcss'

postcss(/* … */)
```

**ES module interop** (Not recommended for library code!)

```jsonc
// tsconfig.json
{
  "compilerOptions": {
    "esModuleInterop": true,
    "module": "commonjs",
    "moduleResolution": "node16"
  }
}
```

```ts
// Unchanged
import postcss from 'postcss'

postcss(/* … */)
```

When compiling to CJS, it is still possible to write ESM-like syntax,
for example:

```jsonc
// Same as import postcss = require('postcss')
import * as postcss from 'postcss'
// Named imports from namespaces are allowed
import { root, Root } from 'postcss'
```

The following changes were made to `tsconfig.json`:

- `lib` was specified explicitly. By default, TypeScript includes the
  `dom` types. This is not desirable, it even causes some conflicts with
  types used by Postcss.
- `allowJs` was removed. When this is enabled, TypeScript treats `.d.ts`
  files matching `.js` files as output. This caused some unexpected
  issues where TypeScript simply ignored type errors.
- `skipLibCheck` was removed. Ideally all types just work together. This
  can be added again later if necessary.
- `esModuleInterop` was removed. Enabling this option causes TypeScript
  to allow code that is otherwise invalid. This may be useful for CLIs
  or website, but is dangerous to use for libraries.

Correcting these options also highlighted some issues in the tests.
These have been resolved. `nanodelay@1` has incorrect type definitions,
so it has been marked using `@ts-expect-error` comments.

In `test/errors.ts` were some type errors. These were marked as
`THROWS`, which signals `check-dts` a type error is expected.
This was changed to `@ts-expect-error`, which works too, but it also
works with other TypeScript tooling.

The `Postcss` type was missing some properties. As a side effect of the
corrected types, these are now available. This also affects the `Helper`
type.

Last, but not least, type definitions have been added for `postcss.mjs`.

Closes #1814
2023-02-16 16:17:58 +01:00
Masafumi Koba 7e96e72c62 Fix Node#warn() return type 2022-02-25 01:25:49 +09:00
Adaline Valentina Simonian f1fa07d292 refactor: make suggested changes 2021-11-18 16:56:31 -08:00
Adaline Valentina Simonian 45097948ff feat: Support ranges for errors and warnings
Allows for better diagnostics in linters, language servers, and plugins.
2021-11-16 17:15:01 -08:00
Andrey SitnikandGitHub 2c6777648a Merge pull request #1582 from hudochenkov/add-document-node-1498
Add Document node and related API (#1498)
2021-05-18 20:46:25 -04:00
Aleks Hudochenkov 205f9a9063 Test custom parser 2021-05-18 23:41:23 +02:00
Aleks Hudochenkov bd17ae8ec9 Remove Node#document() 2021-05-18 02:01:20 +02:00
Jonathan NealandAndrey Sitnik f070b51ff1 feat: Node#assign
The `assign` function lets authors assign multiple properties to a node from a single object.

This can improve code clarity when updating multiple properties while offering a helpful typing experience.
2021-05-17 08:50:29 -04:00
Aleks Hudochenkov 31be3e84d2 Fix types 2021-05-17 10:56:37 +02:00
Aleks Hudochenkov b27fcdd3a8 Specify parent type on a Root node 2021-05-17 02:38:22 +02:00
Aleks Hudochenkov 430ee0d902 Add Document node and related API (#1498) 2021-05-16 20:15:56 +02:00
Andrey Sitnik 843ab11b6e Add Prettier 2021-03-11 19:11:37 -05:00
Andrey Sitnik b6d5183adb Clarify offset/column start value 2020-10-26 05:36:40 -04:00
Ayaz ZaynutdinovandAndrey Sitnik 080c6b3002 Add offset property to position 2020-09-08 22:18:32 -04:00