Skip to content

bug: Using .addPhrase with Angular script optimization causes error that prevents Angular from bootstrapping #53

Description

@cody-01

Expected behavior

I expected .addPhrase to include my added obscene term and build properly.

Actual behavior

Using .addPhrase in an Angular component and optimization: scripts = true in angular.json's build config causes the following error:
Cannot read properties of undefined (reading 'Literal');

This error prevented Angular from bootstrapping

Minimal reproducible example

Add this block to angular.json. "scripts: true" being the one that creates the issue. Seems like something to do with minification.

"optimization": { "styles": { "minify": true, "inlineCritical": true }, "scripts": true, "fonts": true },

Import the package to a component.
import { DataSet, RegExpMatcher, englishDataset, englishRecommendedTransformers, pattern } from 'obscenity';

In ngOnInit, add custom phrases to the DataSet

    const customDataSet = new DataSet()
      .addAll(englishDataset)
      .addPhrase((phrase) => phrase.addPattern(pattern`|damn|`))
      .addPhrase((phrase) => phrase.addPattern(pattern`|hell|`).addWhitelistedTerm('hello'));

    this.matcher = new RegExpMatcher({
      ...customDataSet.build(),
      ...englishRecommendedTransformers,
    });

...

Steps to reproduce

NOTE: This works fine in v0.1.4

  • Configure you Angular project to optimize scripts (minify) in the angular.json file
  • Using an Angular component...
  • Import englishDataset and DataSet
  • In ngOnInit, create a custom dataset that starts with the englishDataset
  • Add custom phrases to that DataSet using addPhrase => addPattern
  • Notice error: Cannot read properties of undefined (reading 'Literal');

Additional context

No response

Node.js version

v18.12.1

Obscenity version

v0.2.0

Priority

  • Low
  • Medium
  • High

Terms

  • I agree to follow the project's Code of Conduct.
  • I have searched existing issues for similar reports.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions